Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Dim a=b".

What type of declaration is this? How can it be used in c#?
Posted
Updated 19-Dec-11 22:59pm
v2

It can't be used in c#, it is a VB code line.
What it does is declare a new variable a and assign it the value of b. Since VB is not type safe, it doesn't car what type a or b are.

C# is type safe. The closest you can get to this are:
C#
dynamic a = b;
or
C#
var a=b;
But it is much, much better to declare a using the correct datatype in the first place, depending on what the datatype of b could be.:
C#
int a = b;

C#
Button a = b;

C#
Control a = b;
 
Share this answer
 
Comments
Uday P.Singh 20-Dec-11 5:15am    
5ed :)
Simon_Whale 20-Dec-11 8:10am    
+5 for just the encouraging people not to use anonymous typing where not necessary!
Declares and allocates storage space for a. Data type of a is not specified, a is initialized with the value of the variable b (see the documentation at MSDN, "Default Data Types and Values" section[^]) for understanding how a datatype is assigned to a (it depends on compiler options).

I'm not an expert, but I think the closest C# statement is
C#
var a = b;
 
Share this answer
 
v2
Comments
Uday P.Singh 20-Dec-11 5:16am    
5ed :)
CPallini 20-Dec-11 5:19am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900