我已經找到答案,確定一個IList<string>
包含一個元素使用不區分大小寫包含:ilist.Contains(element, StringComparer.CurrentCultureIgnoreCase)
C# - 查找不區分大小寫指數的IList
但是我希望做的就是找到內對應的元素本身IList是我正在尋找的元素。例如,如果IList包含{Foo, Bar}
並且我搜索fOo
我希望能夠收到Foo
。
我並不擔心倍數,並且IList似乎沒有包含IndexOf
以外的任何功能,但對我沒有多大幫助。
編輯:由於我使用的IList,而不是名單,我不具備的功能的IndexOf,所以貼在這裏的答案並不能幫助我很多:)
感謝, 阿里克
的可能的複製[如何忽略在列表中的情況下,靈敏度(https://stackoverflow.com/questions/3107765/how-to-ignore-the-case-sensitivity-in-liststring) –
如果你確定沒有重複,那麼在Where()後面加上Single()會給你一個單行的答案:'ilist.Where(l => l.ToLower()== element.ToLower ))。單()'。否則,如果有可能發生重複,Mong的答案會有所幫助。 [這裏](https://stackoverflow.com/questions/21194750/which-is-faster-singlepredicate-or-wherepredicate-single)是一些額外的(可能對你沒有用)信息爲什麼你應該使用'Where() '+'Single()'對'Single(謂詞)'。 –
@MarkoJuvančič我使用IList而不是List,所以我沒有IndexOf函數。我發現這個問題,但沒有多大幫助。 –