c# - Predicate Criteria Not Working When Adding From List<int> -


i have list of int correspond many contract's ids. idea user can add 'favorite' contract id stored in database. retrieve list person filter down datagrid favorite contract shows.

if add hardcoded id list of predicates there no issue, so;

criteria.clear(); if (favouritescheckbox.ischecked == true) {     criteria.add(new predicate<contractmodel>(x => x.id == 6966)); } 

however, when try add list<int> contains ids. so;

if (favouritescheckbox.ischecked == true) {     (int = 0; <= 48; i++)     {         if (favouritecontractlist[i] != 0)         {             criteria.add(new predicate<contractmodel>(x => x.id == favouritecontractlist[i]));         }     } } 

there few things go confuse me. firstly, favouritecontractlist.count results in 50, can't for (int = 0; <= 50; i++). secondly, i've printed out favouritecontractlist[i].tostring() throughout loop , there seems no issue ids being stored. when check combobox filter datagrid left empty grid when try way.

try putting favouritecontractlist[i] variable, so:

if (favouritescheckbox.ischecked == true) {     (int = 0; <= 48; i++)     {         int id = favouritecontractlist[i];         if (id != 0)         {             criteria.add(new predicate<contractmodel>(x => x.id == id));         } } 

something way delays building causes not resolve you'd think would. thinks 'i' 49 when gets around using it. explain why can't let 'i' above 49 -- out of range of 50 ints in list.

i noticed said have 50 items , can't 'i <= 50', since indexing starts @ 0, i=50 51st item (which doesn't exist).


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -