Connecting Tech Pros Worldwide Forums | Help | Site Map

typeof

Michael C#
Guest
 
Posts: n/a
#1: Nov 21 '05
What's the VB equivalent of the C# typeof() operator (it doesn't appear to
be the VB "TypeOf" operator). Thanks.



Derek Harmon
Guest
 
Posts: n/a
#2: Nov 21 '05

re: typeof


"Michael C#" <xyz@abcdef.com> wrote in message news:3bp2e.9673$Z24.3939@fe12.lga...[color=blue]
> What's the VB equivalent of the C# typeof() operator (it doesn't appear to be the VB "TypeOf" operator).[/color]

In C#,

Type t = typeof( String);

In VB.NET,

Dim t As Type = GetType( String);


Derek Harmon


David Anton
Guest
 
Posts: n/a
#3: Nov 21 '05

re: typeof


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:
[color=blue]
> What's the VB equivalent of the C# typeof() operator (it doesn't appear to
> be the VB "TypeOf" operator). Thanks.
>
>
>[/color]
Cor Ligthert
Guest
 
Posts: n/a
#4: Nov 21 '05

re: typeof


Michael,

If typeof ctr Is Label then

Is that what you mean?

Cor


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#5: Nov 21 '05

re: typeof


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#" <xyz@abcdef.com> wrote in message
news:3bp2e.9673$Z24.3939@fe12.lga...
| What's the VB equivalent of the C# typeof() operator (it doesn't appear to
| be the VB "TypeOf" operator). Thanks.
|
|


Supra
Guest
 
Posts: n/a
#6: Nov 21 '05

re: typeof


http://www.harding.edu/USER/fmccown/...omparison.html
;-)

Michael C# wrote:
[color=blue]
>What's the VB equivalent of the C# typeof() operator (it doesn't appear to
>be the VB "TypeOf" operator). Thanks.
>
>
>
>[/color]

Michael C#
Guest
 
Posts: n/a
#7: Nov 21 '05

re: typeof


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#" <xyz@abcdef.com> wrote in message
news:3bp2e.9673$Z24.3939@fe12.lga...[color=blue]
> What's the VB equivalent of the C# typeof() operator (it doesn't appear to
> be the VB "TypeOf" operator). Thanks.
>[/color]


Closed Thread