Hello I need to know how to check if the object of the same type in C#.
Scenario:
class Base_Data{}
class Person : Base_Data { }
class Phone : Base_data { }
class AnotherClass
{
public void CheckObject(Base_Data data)
{
if (data.Equals(Person.GetType()))
{ //<-- Visual Studio 2010 gives me error, says that I am using 'Person' is a type and not a variable.
}
}
}
You could use the
isoperator:Another possibility is to use the
asoperator:Or, starting with C# 7, use a pattern-matching form of the
isoperator that combines the above two: