473,386 Members | 1,610 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,386 software developers and data experts.

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

Similar topics

4
by: Andreas Klemt | last post by:
Hello, what has the better performance and what are you using? Dim myObj As Object = 70 a) Dim myInt As Integer = DirectCast(myObj, Integer) b) Dim myInt As Integer = Convert.ToInt32(myObj) ...
11
by: Tubs | last post by:
i am attempting to write something which can morph itself to whatever comes in and get the value property from it but i don't know what type it is until runtime. I am therefore trying to use...
13
by: Crirus | last post by:
Can I use DirectCast to convert a object to it's base or should I use CType? I have a instance of a class as Object. The run-time tipe is a derived of a class, but I need to refer to that instance...
6
by: Ot | last post by:
I apparently have a bit to learn about Casting and Conversion. I have been thinking of them as the same but a discussion in another thread leads me to believe that this is wrong thinking. I...
5
by: Michael Ramey | last post by:
Hello, There are quite a few ways to convert one object, say an integer to a string. Dim myStr as string dim myInt as integer = 123 myStr = cstr(myInt) myStr = myInt.toString()
6
by: Mark Nethercott | last post by:
I get the following failure when trying to access the builtin properties; An unhandled exception of type 'System.InvalidCastException' occurred in resultsoutput.dll Additional information:...
7
by: Brian Henry | last post by:
is there any speed diffrences between doing Ctype or directcast? I know about the inherite diffrences, but process usage time wise, does one take up more cycles then the other? thanks
1
by: iwdu15 | last post by:
can anyone explain the directcast code...ive tried using it and lookin it up but im lookin for an easy definition and how it works...ive tried using it before byut it throws errors saying it can...
3
by: =?Utf-8?B?TWlrZQ==?= | last post by:
If Visual Studio knows the type, why does the system-generated property use CType instead of DirectCast? DirectCast is more efficient right? For example - Here's what we have for a setting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.