C# keyword default(T) to VB.net

E

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.
 
H

Herfried K. Wagner [MVP]

Eric Cathell said:
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'.
 
J

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


|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.
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top