Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2007

Tip: Looking for answers? Try searching our database.

Type Casting Syntax?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
coconet - 04 Dec 2007 17:29 GMT
I am trying to explicitly cast something "dynamically". The following
code is not working, what is the proper syntax?

  Type foundtype =MyDataTable.Columns[columnname].DataType;
  object myvalue = (foundtype)inputvalue;

The build-time error I get is "The type of namespace 'foundtype' could
not be found".

Thanks.
Jon Skeet [C# MVP] - 04 Dec 2007 17:58 GMT
> I am trying to explicitly cast something "dynamically".

Casts are present to give the *compiler* more information. In other
words, doing them dynamically at execution time bypasses most of the
point. Now, what are you actually trying to do?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

coconet - 04 Dec 2007 19:21 GMT
I wanted to use Convert.ChangeType() actually, I just didn't know it
at the time I posted the question. :)

Thanks.

>> I am trying to explicitly cast something "dynamically".
>
>Casts are present to give the *compiler* more information. In other
>words, doing them dynamically at execution time bypasses most of the
>point. Now, what are you actually trying to do?
Mythran - 05 Dec 2007 16:42 GMT
> I wanted to use Convert.ChangeType() actually, I just didn't know it
> at the time I posted the question. :)
[quoted text clipped - 6 lines]
>>words, doing them dynamically at execution time bypasses most of the
>>point. Now, what are you actually trying to do?

Did ya notice that you are trying to cast an object....to another
type....and then reference it from an object?!?  Why perform the cast at
all?

Mythran

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.