Array.Find with Delegate. What does it return if not found?

I have an Array<Person> myArray and I use the following code

 myArray.Find(o => o.name.Equals("John")); 

This article in the Msdn article reads:

Return value

Type: T

The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.

If I had an Array<int> , the default would be zero. But in my case, I use a class. Say Array<Person> .

What will be the default value for my class and how can I handle a case not found using a delegate?

+7
source share
2 answers

The default value for any reference type (class, interface, delegate) is an empty reference. The default value for any type of value is the value in which all type fields are the default value for this field, so you get 0, \0 , false, etc.

See MSDN for more details.

+10
source

Assuming Person is a reference type, the default value for it will be null.

Therefore, calling Array.Find () will return null if the condition is not met.

+4
source

All Articles