472,342 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 56946
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
I need to do the following but it doesn't compile if(typeof(listBox1.Items) == typeof(string)){ return; } typeof(listBox1.Items) doesn't...
4
by: ichor | last post by:
hi what is the use of the typeof keyword , and how does it differ from the GetType method. i found the GetType method useful but i fail to...
7
by: Mark Miller | last post by:
I am using Reflection.Emit to dynamically build a class. A method of the class to be built requires a Parameter of type "Type". But I don't know how...
3
by: Alberto | last post by:
Can somebody tell me why this typeof doesn't work? foreach (Control myControl in Controls) if (typeof(myControl) == "TextBox")...
1
by: Brien King | last post by:
Ok, I have three classes (The example here is extremely simplified to illustrate the problem) like this: Public Class A Public Sub...
11
by: Jason Kendall | last post by:
Why doesn't the new "IsNot" operator work in conjunction with 'Typeof'?
2
by: Andrew Robinson | last post by:
I am guessing there is a simple solution but given a type T, how can I check for nullability? how can I accomplish the following? bool...
4
by: EManning | last post by:
Using A2003. I've got an option group that has a number of check boxes. I have coding to clear the option group if the user wishes to cancel...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement,...
20
by: rkk | last post by:
Hi, Is there an equivalent typeof macro/method to determine the type of a variable in runtime & most importantly that works well with most known...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.