PC Review


Reply
Thread Tools Rate Thread

DirectCast in .NET 2.0

 
 
Sahil Malik
Guest
Posts: n/a
 
      3rd Jan 2005
I can't find it .. what am I missing?

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




 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      3rd Jan 2005
Sahil,

It's not a C# feature, but a VB feature. What are you trying to do?


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Sahil Malik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I can't find it .. what am I missing?
>
> - Sahil Malik
> http://dotnetjunkies.com/weblog/sahilmalik
>
>
>
>



 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      3rd Jan 2005

>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.
 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      3rd Jan 2005
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]" <(E-Mail Removed)> wrote in
message news:#(E-Mail Removed)...
> Sahil,
>
> It's not a C# feature, but a VB feature. What are you trying to do?
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Sahil Malik" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I can't find it .. what am I missing?
> >
> > - Sahil Malik
> > http://dotnetjunkies.com/weblog/sahilmalik
> >
> >
> >
> >

>
>



 
Reply With Quote
 
Rob Windsor [MVP]
Guest
Posts: n/a
 
      3rd Jan 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I can't find it .. what am I missing?
>
> - Sahil Malik
> http://dotnetjunkies.com/weblog/sahilmalik
>
>
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      3rd Jan 2005
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


 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      3rd Jan 2005
Huh?

"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      3rd Jan 2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I can't find it .. what am I missing?
> >
> > - Sahil Malik
> > http://dotnetjunkies.com/weblog/sahilmalik
> >
> >
> >
> >

>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      3rd Jan 2005
> Huh?
>

"Almost"

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

:-)

Cor


 
Reply With Quote
 
Abhijeet Dev
Guest
Posts: n/a
 
      3rd Jan 2005
should not we use tb = (sender as TextBox);
and then check if tb is null

"Rob Windsor [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I can't find it .. what am I missing?
>>
>> - Sahil Malik
>> http://dotnetjunkies.com/weblog/sahilmalik
>>
>>
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DirectCast kimiraikkonen Microsoft VB .NET 9 11th Jan 2008 08:28 PM
directcast =?Utf-8?B?aXdkdTE1?= Microsoft VB .NET 1 20th Sep 2005 02:56 AM
Bug in DirectCast() ? Guido Kraus Microsoft VB .NET 7 30th Mar 2004 01:11 PM
DirectCast Merlin Microsoft VB .NET 3 17th Mar 2004 05:18 PM
Re: DirectCast Mattias Sjögren Microsoft C# .NET 0 17th Aug 2003 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 AM.