Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract rows from 2D array within a model

Tags:

c#

linq

I am working in C#. I have a class model:

public class CustomerViewModel
{
    public string Name;
    public string[][] values;
    public bool[] flag;
}


I wish to extract values[x][0] from all rows of values where flag==false, using LINQ

like image 790
zeetit Avatar asked Jul 03 '26 04:07

zeetit


1 Answers

Something like this should do it:

var result = custVm.flag.Select((f, i) => new { f, val = custVm.values[i][0] })
                        .Where(i => !i.f)
                        .Select(i => i.val);

For every entry in the flag array, you're mapping the value from the first column of the values array to a new anonyomous object, containing the flag and the value.

You're then filtering this list of anonymous objects by flag == false.

Then you're selecting just the 'value' parts of the anonymous objects.

like image 59
Baldrick Avatar answered Jul 05 '26 16:07

Baldrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!