Need to fetch the first record from Lookup when a condition is satisfied. In below, resId will be key having one or more lists value. In vb, used the below code to fetch the record having resId and record satisfying the below condition. It works perfect.. how can I use the same logic with C#
Lookup<Guid, Class> responseLookup;
result = responseLookup(Guid).FirstOrDefault(
Function(x) catId.Equals(x.catCode)
Tried to convert but was receiving "Method name expected" error
CodePudding user response:
This should work:
responseLookup[Guid].FirstOrDefault(x => catId.Equals(x.catCode))
The =>
is a lambda-expression. In your case a delegate that excepts a single instance from your list and returns a bool
.
CodePudding user response:
Assuming Guid
in responseLookup(Guid)
is some Guid
value, not the type name, the following should work (I suggest using standard naming conventions and refrain from using BCL type names as variable names):
Guid guid = ...;
var result = responseLookup[guid]
.FirstOrDefault(x => catId.Equals(x.catCode));