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 1 # 2 and 2 # 1 will be in the same group ..

For example, take this list as an example

  {"1 # 2", "1 # 6", "1 # 2", "2 # 1"} < / Code>  

I want to add this list to the group like this

  key = 1 # 2 or 2 # 1 value = {"1 # 2", "1 # 2", "2 # 1"} key = 1 # 6 or 6 # 1 value = {"1 # 6"}   

So I base two different keys I want to group the string on

I tried

  list.GroupBy (x => x);   

But in this three key, 1 # 2 , 2 # 1 , 1 # 6 The group performs 1 # 2 or 2 # 1 , 1 # 6

You can try to do something like this:

  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); }}   

This should work, even if there are more than 2 values, etc. 1 # 2 # 3

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -