Quick question: how to compare a Type type (pun not intended) with another type in C#?
I mean, I\'ve a Type typeField and I want to know if it is System.S
If your instance is a Type:
Type typeFiled;
if (typeField == typeof(string))
{
...
}
but if your instance is an object and not a Type use the as operator:
object value;
string text = value as string;
if (text != null)
{
// value is a string and you can do your work here
}
this has the advantage to convert value only once into the specified type.