On Fri, 7 Dec 2007 00:50:06 +1030, Mark Hurd <[EMAIL PROTECTED]> wrote:
>Following on from the thread "another generic query", what is the >simplest way to implement Nullable(Of String) when that IS what you >want. > >E.g. You have a String property and setting it to any value, including >Nothing, needs to be differentiated from its default value say. > >I decided to create > >Structure Box(Of T) > Public Value As T >End Structure > >Then I can use Nullable(Of Box(Of String)) > >which isn't that convoluted... > >Does Box exist somewhere in the framework? > >Is there a better way? > >Regards, >Mark Hurd, B.Sc.(Ma.)(Hons.) > >PS The more complete solution I'm using is: > >Structure Box(Of T) > Public Sub New(ByVal Value As T) > Me.Value = Value > End Sub > Public ReadOnly Value As T >End Structure >... >Private SomeField As Nullable(Of Box(Of String))) = Nothing >... >If SomeField.HasValue Then Use(SomeField.Value.Value) > >=================================== >This list is hosted by DevelopMentorĀ® http://www.develop.com > >View archives and manage your subscription(s) at http://discuss.develop.com null/Nothing is a String variable's default value... If you're overriding what "default" means in your particular context, then you'll also have to override comparison against your default. You cannot use a reference type (like String) with Nullable<T>, so there isn't away to do with Nullable<T>. You'll have to write an new class to handle that. You can also not box a String (i.e. boxing a String does nothing). But, as Barry points out, why? =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com