如何通过linq提取唯一的子字符串

时间:2015-07-19 19:19:47

标签: linq

我有一个数组

{ 
  Line.Column1.Pos,
  Line.Column1.Length,
  Line.Column2.Value,
  Line.Column3.Pos,
  Line.Column3.Length,
  line.Column5.Date
}

如何获取unque子串列表,即 Linq {Column1,Column2,Column3,Column5 }

1 个答案:

答案 0 :(得分:1)

如果你能得到数组中项目的字符串表示,

你可以这样做:

string[] items = 
{ 
    "Line.Column1.Pos", 
    "Line.Column1.Length", 
    "Line.Column2.Value", 
    "Line.Column3.Pos", 
    "Line.Column3.Length", 
    "line.Column5.Date" 
};

var distinctItems = items.
    Select(o => o.Split('.')[1]).
    Distinct().
    ToArray();