Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
現在、「.contains」メソッドを使用してリストを検索し、一致する値を取得しています。
リスト1:
dog bark cat meow lion raw
例えば
if (List1.Contains("dog")) { // Return the value of this list item e.g. "dog bark" }
あなたが望むように聞こえます:
var match = list.FirstOrDefault(x => x.Contains("dog")); if (match != null) { Console.WriteLine(match); }
または、すべての一致を表示するには:
foreach (var match in list.Where(x => x.Contains("dog")) { Console.WriteLine(match); }