Check if KeyValuePair exists with LINQ's FirstOrDefault

后端 未结 6 1173
情书的邮戳
情书的邮戳 2021-02-03 17:03

I have a dictionary of type

Dictionary

I want to return the first instance where a condition is met using

var         


        
6条回答
  •  轮回少年
    2021-02-03 17:11

    A way to check against the default value of a struct such as KeyValuePair without specifying the type is to create a new instance using Activator:

    if (available.Equals(Activator.CreateInstance(available.GetType())))
    {
        Console.WriteLine("Not Found!");
    }
    

提交回复
热议问题