Home > Net >  Linq to an item in the list of combination each other side?
Linq to an item in the list of combination each other side?

Time:02-27

Such as I have the following List
{
{id=1, Name=A},
{id=2, Name=B},
{id=3, Name=C},
{id=4, Name=D},
{id=5, Name=E},
{id=6, Name=F},
}
Want AB AC AD AE AF BC BD BE BF CD CE CF DE DF EF the combination,

CodePudding user response:

 static void Main (string [] args) 
{
Var q=the from a myList in
The from b in myList
Select new {Name=a.N ame + b.N ame};
Q.T oList (). The ForEach (x=& gt;
{
Console. WriteLine (x);
});

Console.ReadLine();
}


CodePudding user response:

 string [] LST=new string [] {" A ", "B", "C", "D", "E", "F"}; 
Var b=LST. SelectMany ((s, I)=& gt; LST. Skip (I + 1), (a, b)=& gt; A + b);
Console. WriteLine (string. Join (Environment. NewLine, b));

CodePudding user response:

In another pattern play

 string [] LST=new string [] {" A ", "B", "C", "D", "E", "F"}; 
LST. ToObservable (.) SelectMany ((s, I)=& gt; LST. Skip (I + 1), (i1 s1, s2, i2)=& gt; S1 + s2). The Subscribe (p=& gt;
{
Console. WriteLine (p);
});
  •  Tags:  
  • LINQ
  • Related