here is what a I'm doing:
object ReturnMatch(System.Type type)
{
foreach(object obj in myObjects)
{
if (obj == type)
{
return obj;
}
}
}
However, if obj is a subclass of type
, it will not match. But I would like the function to return the same way as if I was using the operator is
.
I tried the following, but it won't compile:
if (obj is type) // won't compile in C# 2.0
The best solution I came up with was:
if (obj.GetType().Equals(type) || obj.GetType().IsSubclassOf(type))
Isn't there a way to use operator is
to make the code cleaner?