Home All Groups Group Topic Archive Search About

C# keyword default(T) to VB.net

Author
1 Sep 2006 5:57 PM
Eric Cathell
I can not find the answer for this anywhere. What is the keyword in VB.net
that matches the default(T) generics keywork in vb.net?

C#
return ID == null || ID.Equals(default(IdT));

vb.net
Return ((ID Is Nothing) Or ID.Equals(default(idt)))

default expects and expression.

Thanks.

Author
1 Sep 2006 7:05 PM
Herfried K. Wagner [MVP]
"Eric Cathell" <depictureboy@community.nospam> schrieb:
>I can not find the answer for this anywhere. What is the keyword in VB.net
>that matches the default(T) generics keywork in vb.net?

'Nothing'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
1 Sep 2006 9:43 PM
Jay B. Harlow [MVP - Outlook]
Eric,
As Herfried stated, its "Nothing"

| C#
| return ID == null || ID.Equals(default(IdT));
|
| vb.net
    Return ((ID Is Nothing) Or ID.Equals(Nothing))

NOTE: The above assumes that you have an IEquatable constraint on ID!


If you don't have the constraint, I would define a temporary variable & pass
that:

    Dim [default] As idt
    Return ((ID Is Nothing) Or ID.Equals([default]))

Which implies you could write a generic method:

    Public Function [Default](Of T)() As T
        Return Nothing
    End Function

    Return ((ID Is Nothing) Or ID.Equals([Default](Of idt)()))

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"Eric Cathell" <depictureboy@community.nospam> wrote in message
news:u%236$aAfzGHA.2076@TK2MSFTNGP04.phx.gbl...
|I can not find the answer for this anywhere. What is the keyword in VB.net
| that matches the default(T) generics keywork in vb.net?
|
| C#
| return ID == null || ID.Equals(default(IdT));
|
| vb.net
| Return ((ID Is Nothing) Or ID.Equals(default(idt)))
|
| default expects and expression.
|
| Thanks.
|
|