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
Post a Comment