static void Main(string[] args) { string[] strArray = { "","111","","222","","333"}; Console.WriteLine("输出带有空字符串的数组:"); foreach (string str in strArray) { Console.WriteLine(str); } Console.WriteLine("-------------------------------------------"); //使用lambda表达式过滤掉空字符串 strArray = strArray.Where(s=>!string.IsNullOrEmpty(s)).ToArray(); Console.WriteLine("输出过滤掉空字符串的数组:"); foreach (string str in strArray) { Console.WriteLine(str); } Console.Read(); }
时间: 2024-11-05 14:58:37