How to C# linq GroupBy multiple arrays with array values -


i have array of objects "channel" each have properties

string axis  //times , values correspond each other. lengths same. times[0] value values[0], etc...    float[] times float[] values 

lets there 3 channels in channels array, , float[] "times" values are...

channel[0].times = 1, 2, 3, 4, 5, 6 channel[1].times = 0, 2, 2.5, 3, 5, 6 channel[2].times = 1, 2.5, 3, 4, 5.5, 6 

minichannel object has properties

string axis float value; 

the result looking this...

dictionary<float, minichannel[]> matchingtimes; //float corresponds times value  

matchingtimes[0] contains...

new minichannel0 minichannel.axis = channel[1].axis minichannel.value= channel[1].values[0] 

matchingtimes[1] contains...

new minichannel0 minichannel.axis = channel[0].axis minichannel.value= channel[0].values[0]  new minichannel1 minichannel.axis = channel[2].axis minichannel.value = channel[2].values[0] 

.....

matchingtimes[5.5] contains...

new minichannel0 minichannel.axis = channel[2].axis minichannel.value= channel[2].values[4] 

etc... etc... each time value.

so trying group channels same time , value time string axis.

ive looked around answers in regards groupby linq method, saw people dealing either single array, or array multiple elements, still 1 item each element.

any appreciated.

try this:

idictionary<float, minichannel[]> matchingtimes = channel     .selectmany(c => c.times.select((t, i) => new keyvaluepair<float, minichannel>(t, new minichannel {axis = c.axis, value = c.values[i]})))     .groupby(t => t.key)     .todictionary(t => t.key, t => t.select(c => c.value).toarray()); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -