C# GetType - Why does it need an instance?

R

Richard Coltrane

Hi there,

In VB.net i can just GetType(string) to get the string type? In C# it seems
i need to have or create a non null variable and myvar.GetType(). Is there a
shorthand version of this like VB.net in C#. On a couple of occasion ive
found myself creating a throw away var just so i can gets it type which just
looks dumb.

Thanks
Richard
 
C

Chris Dunaway

Hi there,

In VB.net i can just GetType(string) to get the string type? In C# it seems
i need to have or create a non null variable and myvar.GetType(). Is there a
shorthand version of this like VB.net in C#. On a couple of occasion ive
found myself creating a throw away var just so i can gets it type which just
looks dumb.

GetType is a keyword in VB.Net, not in C#. As James pointed out, the
C# equivalent is typeof
 

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

Top