PC Review


Reply
Thread Tools Rate Thread

ChangeType to Nullable<> does not work

 
 
=?Utf-8?B?c3RlZmFuc2U=?=
Guest
Posts: n/a
 
      8th Jul 2004
Hi,
Could someone explain why this works the way it does..
string s = "55";
int i1 = Convert.ChangeType(s, typeof(int)); // this is ok
int? i2 = Convert.ChangeType(s, typeof(int?)); // this fails!

My opinion is that the normal Int32 and Nullable<Int32> shall have the same
features etc (more for the nullable). In the above example the conversion should be ok for both cases.
If the string wouldn't have been an ok number they should fail (exception) in
the same way.
(Preferrable maybe the Nullable<> cast shouldn't throw any exception and
return an instance without value.)

another nullable issue (maybe related):
http://lab.msdn.microsoft.com/produc...b-127f0fceeedb

Regards & TIA
Stefan

 
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
Difference between nullable class and nullable<> structure Raj Microsoft C# .NET 31 19th Oct 2009 11:01 PM
FileSystemEventArgs, e.ChangeType enumeration Yankee Imperialist Dog! Microsoft C# .NET 1 30th Sep 2008 09:12 PM
Adding a nullable datetime column to a datatable does not work GG Microsoft C# .NET 5 22nd Jul 2006 09:30 PM
Does RI with nullable FKs really work????? =?Utf-8?B?dG1qMDAzNDU=?= Microsoft Access Database Table Design 2 19th Jun 2005 06:22 PM
nullable types. why no support for nullable string Sakoulakis Microsoft C# .NET 3 6th Aug 2004 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 PM.