C#去除数组空格

       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();
        }

 

posted @ 2016-12-07 13:06  雅比斯  阅读(4095)  评论(0编辑  收藏  举报