You should learn to use the debugger ASAP. Set a breakpoint on the first line of your method, and step through it line by line, examining the values of the variables. You'll quickly see which one is
null
when you don't expect it to be.
The most likely cause is that the
Find
method is returning
null
, so you get a
NullReferenceException
when you try to access a property on the
_Dealer
variable. The simple solution is to test the variable before you try to use it.
if (_Dealer != null)
{
foreach (Dealer item in dlist)
{
if (item.name == _Dealer.name)
{
Console.WriteLine("Match Found");
}
}
}