Newbie
Newbie

Reputation: 1111

Convert list to double[][] in C#3.0

Given

List<double> x1 = new List<double> { -0.2718, -0.2240, -0.1275, -0.0810, 0.0349, -0.5067, 0.0094, -0.4404, -0.1212 };
List<double> x2 = new List<double> { 0.0330, -0.6463, 0.1226, -0.3304, 0.4764, -0.4159, 0.4209, -0.4070, -0.2090 };

How can I make as double[][] X at runtime(programatically).

I mean to say if the output I get if I run

double[][] X = { new double[] 
{ -0.2718, -0.2240, -0.1275, -0.0810, 0.0349, -0.5067, 0.0094, -0.4404, -0.1212 }, 
new double[] { 0.0330, -0.6463, 0.1226, -0.3304, 0.4764, -0.4159, 0.4209, -0.4070, -0.2090 } };

Using C#3.0

Thanks

Upvotes: 0

Views: 137

Answers (2)

Andrey
Andrey

Reputation: 60065

double[][] X = new double[][] { x1.ToArray(), x2.ToArray() };

Upvotes: 1

Marcelo Cantos
Marcelo Cantos

Reputation: 185862

double[][] X = new[] { x1.ToArray(), x2.ToArray() };

Upvotes: 2

Related Questions