c# - simple linq issue, but I can't figure it out -
c# - simple linq issue, but I can't figure it out -
i have simple linq issue. i'm trying query list , match fellow member id lists id , homecoming text:
var idtext = idmethod(membid); var t = ctext in cidtext ctext.cid.tostring() == membid select cxt.c_id; viewbag.thisid = t.tostring();
all returns is:
system.linq.enumerable+whereselectarrayiterator`2[pu15.models.c_id,system.int32]
but never changes or shows want show.
what doing wrong?
you want utilize single
or singleordefault
or first
or firstordefault
, depending on want exactly, e.g.:
viewbag.thisid = t.single();
single
throw exception if there more 1 result or if there no results.
if you'll utilize singleordefault
instead homecoming null
in case of more 1 result or no result.
first
on other hand fail empty collection - when there more 1 element homecoming first one.
the tolerant, firstordefault
homecoming null
empty result list, , first element if there more one.
c# .net linq
Comments
Post a Comment