c# - Grouping strings based on two keys -
I have a list of strings with each string, which is different from I want to do group strings such as For example, take this list as an example I want to add this list to the group like this So I base two different keys I want to group the string on I tried But in this three key, You can try to do something like this: This should work, even if there are more than 2 values, etc. 1 # 2 # 3 # . >
1 # 2 and
2 # 1 will be in the same group ..
{"1 # 2", "1 # 6", "1 # 2", "2 # 1"} < / Code>
key = 1 # 2 or 2 # 1 value = {"1 # 2", "1 # 2", "2 # 1"} key = 1 # 6 or 6 # 1 value = {"1 # 6"}
list.GroupBy (x => x);
1 # 2 ,
2 # 1 ,
1 # 6 The group performs
1 # 2 or 2 # 1 ,
1 # 6
void Main () {var list = new string [] {" 1 # 2 ", "1 # 2", "2 # 1"}; Var result = list.GroupBy (x => x.Split ('#'). Order b (y = & gt; y). Overgraduate (a, b) => a + "#" + b )); // should output only one key - foreach # 2 (result in var key) {Console.WriteLine (key); }}
Comments
Post a Comment