+ 1
Why are we using var in c# and what's differents between var and int in c#???
2 Antworten
+ 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