+ 1

Why are we using var in c# and what's differents between var and int in c#???

22nd Dec 2016, 7:29 PM
Rajinur Rahman
Rajinur Rahman - avatar
2 Réponses
+ 7
"var" is an implicit data type which means the compiler determines what type the value that is assigned to the variable is. Also sometimes used as a short hand way of instantiating data structures. "int" is an explicit data type which means you can only assign integer values to the declared variable whereas "var" allows you to assign anything to the declared variable whether thats strings, double, char, other objects etc. e.g var name = "example"; //okay var number = 47.8; // okay var character = 'h'; //okay var list = new List(); // okay int x = 50; // okay int y = " y"; // error
23rd Dec 2016, 1:04 AM
Ousmane Diaw
22nd Dec 2016, 7:32 PM
Valen.H. ~
Valen.H. ~ - avatar