I have an array of an object say ClientsDTO[]. There is a property namely Tin in the object. I want to check if a value is present in the array. I have one way of checking this i.e. using the LINQ query and getting the list of objects which satisfies the condition. If the returned list is null then the value is not present in the array. If the list exists then value is present in the array. The following is a sample code.
I want to know is there a better way than this i.e. something more elegant and with better performance. I am using VS 2008, 3.5 framework.
ClientsDTO[] client = new ClientsDTO[10];
var lstclient = client.Where(c => c.TIN == anyNumber).FirstOrDefault();
if (lstclient == null)
{
//value present in array
}
else
{
//value not present
}
Thanks in advance!