使用Lambda的表達式來過濾符合條件的數據。下面的代碼實現,是把字符陣列中,把名字長度等於3元素找出來。
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); } } }
運行結果:


