Comparing types

  • Thread starter Thread starter Mike J
  • Start date Start date
M

Mike J

Hi..need help comparing types
example method

istypeof(object someobj)
{
if (someobj=int32)
}

ya kinda get my idea here....
MJ
 
Mike J said:
Hi..need help comparing types
example method

istypeof(object someobj)
{
if (someobj=int32)
}

You can use the operator "is":

if (someobj is Int32) ....

Note that if you try this with a class instead of an int32, the
condition will be true not only if the object is of that class, but also if
it is of an inherited class.
 
Mike J said:
Hi..need help comparing types
example method

istypeof(object someobj)
{
if (someobj=int32)
}

if (someobj is Int32)

or

if (someobj.GetType() == typeof(Int32))

depending one what you really mean by "comparing types".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top