469,934 Members | 2,358 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DirectCast in .NET 2.0

I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Nov 16 '05 #1
10 8585
Sahil,

It's not a C# feature, but a VB feature. What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

Nov 16 '05 #2
I can't find it .. what am I missing?


Wrong language perhaps? DirectCast is a VB.NET keyword, this is a C#
newsgroup....

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #3
Well I'm trying to cast my objects in a standard remoting like scenario. I
was a DirectCast fan .. (over CType in VB)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:#L**************@TK2MSFTNGP09.phx.gbl...
Sahil,

It's not a C# feature, but a VB feature. What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Nov 16 '05 #4
The closest equivalent in C# is to put the type you want to cast to in
parenthesis in front of the reference variable you want to cast. Note that
both will fail with an exception if the cast is invalid.

Dim tb As TextBox
tb = DirectCast(Sender, TextBox)

TextBox tb;
tb = (TextBox)sender;

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

Nov 16 '05 #5
Sahil,

I know nothing about Net 2.0

However I am almost sure that especially Jay wants to help you about this in
the VBNet language group, and when you ask it him he will give all C#
answers as well..

:-)

Cor
Nov 16 '05 #6
Huh?

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uR**************@TK2MSFTNGP14.phx.gbl...
Sahil,

I know nothing about Net 2.0

However I am almost sure that especially Jay wants to help you about this
in the VBNet language group, and when you ask it him he will give all C#
answers as well..

:-)

Cor

Nov 16 '05 #7
Thanks Rob. I thought I had used DirectCast in C# too .. :-/ ... I've been
programming in both C# and VB.NET concurrently which is why I end up writing
code that looks like this.

Dim conn as SqlConnection ;

And yeah VB.NET 2.0 does have DirectCast.

Thanks for your replies gentlemen !

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


"Rob Windsor [MVP]" <ro*****************@gmail.com> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
The closest equivalent in C# is to put the type you want to cast to in
parenthesis in front of the reference variable you want to cast. Note that
both will fail with an exception if the cast is invalid.

Dim tb As TextBox
tb = DirectCast(Sender, TextBox)

TextBox tb;
tb = (TextBox)sender;

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Nov 16 '05 #8
> Huh?

"Almost"

I did not know you would read this now you see how much trust I have in you.

:-)

Cor
Nov 16 '05 #9
should not we use tb = (sender as TextBox);
and then check if tb is null

"Rob Windsor [MVP]" <ro*****************@gmail.com> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
The closest equivalent in C# is to put the type you want to cast to in
parenthesis in front of the reference variable you want to cast. Note that
both will fail with an exception if the cast is invalid.

Dim tb As TextBox
tb = DirectCast(Sender, TextBox)

TextBox tb;
tb = (TextBox)sender;

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Nov 16 '05 #10
Yes, you can use the "as" operator to do a safe cast but that is not what
the original poster was asking about.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Abhijeet Dev" <ms****@abhijeet-dev.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
should not we use tb = (sender as TextBox);
and then check if tb is null

"Rob Windsor [MVP]" <ro*****************@gmail.com> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
The closest equivalent in C# is to put the type you want to cast to in
parenthesis in front of the reference variable you want to cast. Note
that both will fail with an exception if the cast is invalid.

Dim tb As TextBox
tb = DirectCast(Sender, TextBox)

TextBox tb;
tb = (TextBox)sender;

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I can't find it .. what am I missing?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik



Nov 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Tubs | last post: by
13 posts views Thread by Crirus | last post: by
6 posts views Thread by Ot | last post: by
6 posts views Thread by Mark Nethercott | last post: by
7 posts views Thread by Brian Henry | last post: by
1 post views Thread by iwdu15 | last post: by
3 posts views Thread by =?Utf-8?B?TWlrZQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.