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 / October 2007

Tip: Looking for answers? Try searching our database.

How to get value of nullable of unknown type??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hvj@paralax.nl - 11 Oct 2007 06:35 GMT
Hi,

I have a situation that I have a nullable type that can be a int?,
double? or any other nullable type. How can I get the contained value
of the nullable without knowing its type.

I read that in the .NET2.0 beta2 there used to be a INullable
interface that could be used for this, but that interface was
skipped.

Thanks,
Henk
robert.oh. - 11 Oct 2007 09:44 GMT
Hi,

I'm not sure if it's the solution to your answer, but maybe
'nullableType.GetType().BaseType' can give you the desired type.

HTH

Signature

*--              robert.oh.              --*

> Hi,
>
[quoted text clipped - 8 lines]
> Thanks,
> Henk
Jon Skeet [C# MVP] - 11 Oct 2007 13:10 GMT
On Oct 11, 6:35 am, h...@paralax.nl wrote:
> I have a situation that I have a nullable type that can be a int?,
> double? or any other nullable type. How can I get the contained value
> of the nullable without knowing its type.

Just box it, and the result will either be the boxed value, or null.

It's not clear to me what sort of interface you'd be looking to use
for this anyway.

Jon
hvj@paralax.nl - 15 Oct 2007 14:41 GMT
> On Oct 11, 6:35 am, h...@paralax.nl wrote:
>
[quoted text clipped - 8 lines]
>
> Jon

Thanks,

Your sollution transforms the problem to 'how can I get the content of
a boxed value without knowing the boxed type', which is as far as I
know
1 checking the type
2 assigning to a reference of that type.
Jon Skeet [C# MVP] - 15 Oct 2007 17:54 GMT
> > On Oct 11, 6:35 am, h...@paralax.nl wrote:
> >
[quoted text clipped - 12 lines]
> 1 checking the type
> 2 assigning to a reference of that type.

Well how would you possibly represent the value in the first place?
What kind of variable could hold it? Surely it's just "object", in
which case the boxed value is exactly the right answer in the first
place.

It would be very helpful if you could post some code which would try to
use this, so we could get more of an idea of your requirements.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

hvj@paralax.nl - 16 Oct 2007 09:31 GMT
>  <h...@paralax.nl> wrote:
> > > On Oct 11, 6:35 am, h...@paralax.nl wrote:
[quoted text clipped - 27 lines]
>
> - Show quoted text -

Thanks,

You've been very helpfull allready. The boxing does it.

Regards,
Henk

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.