469,366 Members | 2,205 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

typeof

What's the VB equivalent of the C# typeof() operator (it doesn't appear to
be the VB "TypeOf" operator). Thanks.
Nov 21 '05 #1
6 56245
"Michael C#" <xy*@abcdef.com> wrote in message news:3b*****************@fe12.lga...
What's the VB equivalent of the C# typeof() operator (it doesn't appear to be the VB "TypeOf" operator).


In C#,

Type t = typeof( String);

In VB.NET,

Dim t As Type = GetType( String);
Derek Harmon
Nov 21 '05 #2
Some of the same keywords have deceptively similar, but different, meanings
between VB and C#:
VB’s global GetType method is equivalent to C#’s typeof operator,
VB’s TypeOf–Is operator is equivalent to C#’s “is” operator,
and of course, "Is" in VB is "==" in C#...

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

"Michael C#" wrote:
What's the VB equivalent of the C# typeof() operator (it doesn't appear to
be the VB "TypeOf" operator). Thanks.

Nov 21 '05 #3
Michael,

If typeof ctr Is Label then

Is that what you mean?

Cor
Nov 21 '05 #4
Michael,
As the others suggest the GetType keyword is equivalent to C#'s typeof
keyword.

Not to be confused with the Type.GetType method/function.

The GetType keyword expects an identifier, while Type.GetType expects a
String.

Dim t1 As Type = GetType(Integer)
Dim t2 As Type = Type.GetType("System.Int32")

For known types I find the GetType keyword is better as you receive compile
errors if you miss type the identifier. I reserve Type.GetType for types
that are only known at runtime, such as ones read from my app.config or XML
schema files.

Hope this helps
Jay
"Michael C#" <xy*@abcdef.com> wrote in message
news:3b*****************@fe12.lga...
| What's the VB equivalent of the C# typeof() operator (it doesn't appear to
| be the VB "TypeOf" operator). Thanks.
|
|
Nov 21 '05 #5
http://www.harding.edu/USER/fmccown/...omparison.html
;-)

Michael C# wrote:
What's the VB equivalent of the C# typeof() operator (it doesn't appear to
be the VB "TypeOf" operator). Thanks.


Nov 21 '05 #6
Thanks for the answers guys. I was actually trying to convert a small app
that used the C# typeof operator. Now that I know about GetType, I can
finish it up :) Thanks again.

"Michael C#" <xy*@abcdef.com> wrote in message
news:3b*****************@fe12.lga...
What's the VB equivalent of the C# typeof() operator (it doesn't appear to
be the VB "TypeOf" operator). Thanks.

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Eric | last post: by
4 posts views Thread by ichor | last post: by
3 posts views Thread by Alberto | last post: by
1 post views Thread by Brien King | last post: by
11 posts views Thread by Jason Kendall | last post: by
2 posts views Thread by Andrew Robinson | last post: by
20 posts views Thread by rkk | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.