1

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

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
4

2 回答 2

6
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();
于 2012-09-06T05:18:09.560 回答
0

像这样的东西怎么样

var pp = arrs.Select(x => x.StartsWith(".") ? x : "." + x);
于 2012-09-06T05:20:26.367 回答