Multiple List<double> to Jagged Array C# [duplicate]

  • A+
Category:Languages

This question already has an answer here:

I have 3 lists which their values are obtained dynamically

List<double> input = new List<double>(); List<double> time = new List<double>(); List<double> censor = new List<double>(); 

How can I convert/combine to double[][] as the example below in an efficient way?

double[][] example = {     //             input  time censor     new double[] {   50,    1,    0   },     new double[] {   70,    2,    1   },     new double[] {   45,    3,    0   },     new double[] {   35,    5,    0   },     new double[] {   62,    7,    1   },     new double[] {   50,   11,    0   },     new double[] {   45,    4,    0   },     new double[] {   57,    6,    0   },     new double[] {   32,    8,    0   },     new double[] {   57,    9,    1   },     new double[] {   60,   10,    1   }, }; 

 


You could do this

List<double> input = new List<double>(); List<double> time = new List<double>(); List<double> censor = new List<double>();  var results = new double[input.Count][];  for (var i = 0; i < input.Count; i++)    results[i] = new []{ input[i] , time[i] , censor[i] }; 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: