Picking up C#, can't seem to find any useful reference to this, other than examples.
So, what is Dim in C#?
The Visual Basic compiler uses the Dim statement to determine the variable's data type and other information, such as what code can access the variable. The following example declares a variable to hold an Integer value. You can specify any data type or the name of an enumeration, structure, class, or interface.
Description. Declares and allocates storage space in memory for variables. The Dim statement is used either at the start of a procedure or the start of a module to declare a variable of a particular data type.
Use the Dim statement at the module or procedure level to declare the data type of a variable. For example, the following statement declares a variable as an Integer. Also use a Dim statement to declare the object type of a variable. The following declares a variable for a new instance of a worksheet.
Variable Declaration in VB.Net. The Dim statement is used for variable declaration and storage allocation for one or more variables. The Dim statement is used at module, class, structure, procedure or block level.
In VB, Dim
declares a variable of a particular type (or of variable type, if you don't specify one). If you Dim x as Foo
, that declares a variable of type Foo
called x
.
In C#, the equivalent is to state the type followed by the variable's name, as in:
Foo x;
int i;
You can also assign in the same step:
Foo x = new Foo();
int i = 6;
C# supports type inference, so you can also do:
// Compiler infers type of x and i based on this assignment.
var x = new Foo(); // x is now of type Foo
var i = 10; // i is now of type int
A Dim
without a corresponding type in VB is similar to declaring a type as Object
in C#:
object o = ...; // An object instance can hold any value or reference type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With