使用Lambda的表示式來過濾符合條件的資料。下面的程式碼實現,是把字元陣列中,把名字長度等於3元素找出來。
![](https://i.iter01.com/images/86153736c3d440f2e7d2df2432d97112d2ef05f0cb7522cf2307c3de9447249a.gif)
class Bv { public void LambdaExpression() { string[] names = new string[] { "insus", "leo", "yang", "Joe", "Michael" }; var result = names.Where(x => x.Length == 3); foreach (string s in result) { Console.WriteLine(s); } } }
執行結果: