I want to create a class which wraps a list of structures.
I have the following code:
public struct MyData
{
public int ID;
public string Description;
}
public class MyClass
{
private List<MyData> data;
public bool Contains(string desc)
{
if (data != null)
{
return data.Contains(item => item.Description.Contains(desc));
}
return false;
}
}
I can’t see why I’m unable to use a Lambda expression, the error that I get is:
Cannot convert lambda expression to type 'MyApp.MyData' because it is not a delegate type
In your case Contains expects you to pass it a
MyData, if you want to use a lambda for comparison then use Any