Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Get all combinations for ▶different◀ Id's ♦
//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 ( see the for-loop ). 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) { /*▶*/LS target=new LS(); for(int i=1;i<int.MaxValue;++i){ // --- --- --- --- --- --- --- --- var selected=TheList().Where(x=>x.Item1==i).Select(x=>x.Item2); if(0==selected.Count())break; if(i==1){target=selected.ToList();continue;} LS tmp=target;target=new LS(); tmp.ForEach(x=>{ selected.ToList().ForEach(y=>target.Add(x+","+y)); //selected.Aggregate(target,(t,y)=>{t.Add(x+","+y);return t;}); }); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- /*▶*/target.ForEach(Console.WriteLine); Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
Nested Namespace
/*Dizide bulunan sayıların en büyük iki ve en küçük ikisini bulma*/
Get missed element in integer collection
Test
divisão
asxsdxsd
Contraseña final
sfdcsddxasdxsd
Evo Ivana da budes fancy :D
Nullable type - Value Exception