|
-
Aug 19th, 2008, 05:31 PM
#1
Thread Starter
Hyperactive Member
[2005] Nullable Structures
Visual Studio 2008 introduced a way to specify that you want a nullable instance of a structure with the following:
VB Code:
Option Strict On
Option Explicit On
Public Class Form1
Private Enum myEnum
Item1
Item2
Item3
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim someValue As myEnum?
MessageBox.Show(someValue.ToString)
End Sub
End Class
This is valid regardless of whether you are compiling to 2.0, 3.0 or 3.5. My issue is, the project I am working on is made in visual studio 2005. At this time, we are unable to use visual studio 2008 for development; so I would like to know how this is done in 2.0? I assume it's possible considering I can compile to 2.0 in VS2008 using this syntax.
Thanks.
-
Aug 19th, 2008, 05:37 PM
#2
Re: [2005] Nullable Structures
How about:
Code:
Dim someValue As Nullable(Of myEnum) = Nothing
MessageBox.Show(someValue.ToString)
All though it looks like this will hinder intellisense for the someValue object.
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Aug 19th, 2008, 05:45 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] Nullable Structures
Thanks
I had considered that, but I was kind of hoping there was a way to apply a tag to the enumeration (or any structure). That way the value is still nullable, but intellisense is preserved.
-
Aug 19th, 2008, 09:50 PM
#4
Re: [2005] Nullable Structures
Nothing has changed in the .NET Framework for nullable types since .NET 2.0 was released. All that has changed is that VB 2008 added the same shorthand for declaring nullable types as C# has from the start. "myEnum?" is just a shorthand for "Nullable(Of myEnum)". That's all. There is no difference between the two as far as implementation is concerned.
That said, nullables are generic, hence the "(Of myEnum)" part. As such, you get just as much Intellisense with nullables as you do with other generics, which is to say that you full Intellisense. Remember, though, that if you declare a variable as a nullable type of T then the variable is NOT type T. It is type T? or Nullable(Of T). The object's Value property is type T.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|