Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB equivalent for C#'s default(T)

What is VB's equivalent for C#'s default(T) - the default operator

like image 487
Hath Avatar asked May 07 '09 10:05

Hath


People also ask

Is VB like C#?

Though C# and VB.NET are syntactically very different, that is where the differences mostly end. Microsoft developed both of these languages to be part of the same . NET Framework development platform. They are both developed, managed, and supported by the same language development team at Microsoft.

Is VB better than C#?

Even though there is less prominence of VB.NET community, but still we can say VB.NET is better than C#. 1. VB.NET uses implicit casting and makes it easier to code whereas in C# there are lot of casting and conversions needs to be done for the same lines of code.

Is VB.NET similar to C++?

You are right, C++ and VB are two completely different languages and have quite a few fundamental differences (managed vs. unmanaged being a major one that comes to mind...).

What is a VB module in C#?

In VB, a module is used to store loose code accessible from elsewhere in the application without having to first initialize something. The state of the variable can be easily set or changed and that continues to carry on that value throughout. For the same work in C#< use a static class.


1 Answers

It's any of these:

Dim variable As T Dim variable As T = Nothing Dim variable As New T() Dim variable As T = CType(Nothing, T) 'this is suggested by reflector 

Assigning Nothing even to value types is perfectly fine in VB.NET. And the latter is only possible if you specify either New, or Structure constraint for the generic type.

like image 172
Anton Gogolev Avatar answered Sep 25 '22 08:09

Anton Gogolev