Is there a way to get the index of an item in a case-sensitive list?
List<string> sl = new List<string>() { "a","b","c"}; int result = sl.IndexOf("B"); // should be 1 instead of -1
Try the following: . Therefore, there is no direct way to use IndexOf with the String Comparison option for LIST, in order to achieve the result of the desire, you need to use the Lambda expression.
int result = sl.FindIndex(x => x.Equals("B",StringComparison.OrdinalIgnoreCase));
You can use a method IndexOf()that takes a type StringComparison:
IndexOf()
StringComparison
string s = "foobarbaz"; int index = s.IndexOf("BAR", StringComparison.CurrentCultureIgnoreCase); // index = 3
If the string is not found, IndexOf()returns -1.
-1
Find a case insensitive substring - C #
IndexOf # ComparisonType, :
sl.IndexOf("yourValue", StringComparison.CurrentCultureIgnoreCase)
sl.IndexOf("yourValue", StringComparison.OrdinalIgnoreCase)
Source: https://habr.com/ru/post/1654317/More articles:Finding json related data - jsonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1654313/chrome-fetch-takes-too-long&usg=ALkJrhgyDogWNBvgCPVANMdsEWXwyNeBmgDebugging Exceptions Caused by the Visual Studio Extension - debuggingInsert a specific identifier in the identification field - sql-serverБезопасное использование longjmp/setjmp с изменчивым - cdata binding should include a layout file - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1654319/how-to-add-members-to-an-existing-definition-in-flowjs&usg=ALkJrhi6us_hTfJKagmEMMCc95WuLLHklAКак я могу программно получить доступ к DocStrings? - docstringBASH - getting a UID on a shell script doesn't work - bashC # - Adding a UserControl to another thread throws an exception even after a call - multithreadingAll Articles