473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 57126
"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 work at all. My listBox has 2 types of items in...
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 understand the use of the typeof method. i have tried...
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 to use Emit to pass a call of "typeof()" to the...
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") ((TextBox)myControl).Text = string.Empty; Thank you very much
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 DoSomething(ByVal myClass) If TypeOf myClass IS A Then ' '...
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 nullable = typeof(int).IsNullable; // false 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 their choice. This coding also clears the rest of the...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
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 C compilers? gcc compiler supports typeof()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.