Testing type of variables

  • Thread starter Thread starter Paul K
  • Start date Start date
P

Paul K

I have looked around a little bit in MSDN, but haven't
found an answer to my question:

Does C# support a function like VB's IsNumeric() (or any
other function(s) that can determine if a value is a
specific type)?

Thanks!

Paul K
 
Typing your methods is one way. If you need general passing such as
ValueType or object then check the type in if blocks or a switch block:

public string GetType(ValueType vt)
{
if ( vt.GetType() == typeof(int) )
return "Type is int.";
if ( vt.GetType() == typeof(uint) )
return "Type is uint.";
return "Sorry, not my type.";
}
 
Paul ,
I have looked around a little bit in MSDN, but haven't
found an answer to my question:

Does C# support a function like VB's IsNumeric() (or any
other function(s) that can determine if a value is a
specific type)?

Besides the other options check out the "is" operator in the help. There is
a decent code example too.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/csref/html/vclrfIsPG.htm

Regards,

Randy
 
Back
Top