c# - Filter array of string with select and a bool array -



c# - Filter array of string with select and a bool array -

i need element of string array index in array of bool true. in c#, looking select don't know how utilize on index

string[] contentarray = {"id","name","username"}; bool[] selectionarray = {false,true,false};

i think you're looking for:

ienumerable<string> strings = contentarray.where((str, index) => selectionarray[index]);

which illustration yield ienumerable<string> containing "name".

however, if selectionarray shorter contentarray, index out of bounds exception.

if that's possible, add together length check, assuming want index greater length of selectionarray homecoming false:

ienumerable<string> strings = contentarray.where( (str, index) => index < selectionarray.length && selectionarray[index]);

c# .net

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -