我只想将所有这些查询作为一个查询运行。

string[] arrs = new string[] { ".sds", ".pps", "tbt", "dd." };

string[] val= (from string i in arrs
               where !i.StartsWith(".")
               select "."+i).ToArray();

string[] val1 = (from i in arrs
                 where i.StartsWith(".")
                 select i).ToArray();

var p = val1.Union(val);//get value in single array.e

最佳答案

var p = (from s in arrs
         select s.StartsWith(".") ? s : "." + s).ToArray();


或非查询语法:

var p = arrs.Select(s => s.StartsWith(".") ? s : "." + s)
            .ToArray();


并且您不希望像.Distinct()一样重复{ "foo", ".foo" }

var p = arrs.Select(s => s.StartsWith(".") ? s : "." + s)
            .Distinct()
            .ToArray();

关于c# - 如何在字符串中添加点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12293344/

10-13 01:55