I have structure,
public struct Test
{
public int int1;
public string str;
}
and in my code I have,
List<Test> list = new List<Test>()
{
new Test(){ int1 =1, str="abc" },
new Test(){ int1 =2, str="abc" }
};
When I am trying to use SingleOrDefault on List<Test> list with search criteria int1 value equals 3
Test result = list.SingleOrDefault(o => o.int1 == 3);
Here result have value with default values, means int1 = 0 and str = null. Here I want null value if search criteria not satisfied. Anyone point me How I can do this?
You will not get null returned because
Testis a struct, a value type. ChangeTestto a class and it will return null.