Bro*_*ass 15
var myArray = S.Select( x => new [] { x.A, x.B })
.SelectMany( x => x)
.Where( x=> !string.IsNullOrEmpty(x))
.Distinct()
.ToArray();
Run Code Online (Sandbox Code Playgroud)
上面只有在结果集合上有唯一约束时才有效 - 如果你需要对A和B的集合有唯一约束,则以下方法可行:
var As = S.Select(x => x.A)
.Where( x=> !string.IsNullOrEmpty(x))
.Distinct();
var Bs = S.Select(x => x.B)
.Where( x=> !string.IsNullOrEmpty(x))
.Distinct();
Run Code Online (Sandbox Code Playgroud)
var myArray = new [] {As,Bs} .SelectMany(x => x).ToArray();
var myArray = As.Concat(Bs).ToArray();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15615 次 |
最近记录: |