c# - Array.Find<List<Status>> Error: List<Status> does not contain a definition for 'StatusID' -
i tried finding similar issue one.. wondering if can point out flaw code. have list called statuses of type status class, class looks this:
public class status { public int statusid { get; set; } public string statusdescr { get; set; } public string statustype { get; set; } } i retrieve array/list of records sql , want find statusdescr using known statusid:
list<status> statuses = status_get(inputaction, datadef); var inputstatusid = foodata["statusid"]; string statusdescr = array.find<list<status>>(statuses, item => item.statusid == inputstatusid).statusdescr; but error on item.statusid in 3rd line saying: 'list<status> not contain definition 'statusid' , no extension method 'statusid' accepting first argument of type 'list<status>' found'
obviously because statusid exists on type status, not list<status>. if change array.find<status>, error on statuses saying: `cannot convert '...list<...datatypes.view.status>' '...datatypes.view.status[]'.
basically don't care if statuses list, array, dynamic, etc.. want retrieve statusdescr status object matching statusid. ideas on data types? should use besides array.find?
edit: if take out data type after find this:
array.find(statuses, item => item.statusid == inputstatusid).statusdescr; i error on find saying: type arguments method 'array.find(t[], predicate)' cannot inferred usage. try specifying type arguments explicitly
var result = statuses.firstordefault(x=> x.statusid == inputstatusid); string statusdescr = result?.statusdescr; you need this.
here check dotnet fiddle
Comments
Post a Comment