Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Get all combinations for ▶different◀ Id's ( GroupBy version ) ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 // in reply to the thread // https://social.msdn.microsoft.com/Forums/WindowsServer/en-us/b12e4766-cd22-455d-9474-46c4b865dd45/help-needed-to-get-combinations-in-a-list-of-objects?forum=csharpgeneral // which is similar to // http://stackoverflow.com/questions/10519619/create-all-possible-combinations-of-items-in-a-list-using-linq-and-c-sharp // NOTICE that the quantity of ▶different◀ Id's is, theoretically, UNLIMITED. namespace Rextester { using LS=List<string>; using T2=Tuple<int,string>; using LT2=List<Tuple<int,string>>; class Program { static LT2 TheList(){ return new LT2{ new T2(3,"cotton"), new T2(3,"silk"), new T2(1,"red"), new T2(1,"blue"), new T2(2,"medium"), new T2(2,"small"), new T2(2,"large"), new T2(1,"green"), }; } // ----------------------------------------------------------------------- public static void Main(string[] args) { /*1▶*/LS target=new LS(); /*2▶*/TheList().GroupBy(x=>x.Item1).OrderBy(x=>x.Key).ToList().ForEach(x=>{ if(0==target.Count){ target=x.Select(y=>y.Item2).ToList(); }else{ LS tmp=target;target=new LS(); tmp.ForEach(y=>{ x.Select(z=>z.Item2).ToList().ForEach(z=>target.Add(y+","+z)); }); } }); /*3▶*/target.ForEach(Console.WriteLine); Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
ReplaceNotExpectedCharacters
pattern2
normalised pagination
test2
Testing 004
Unity Character Controller Version 1
Practical
QuickSort
Create RFReader HardwareConfig
Jp-trize