0
What is the difference between "var" Datatype and int, double, string?
In c# we have different types of datatypes we use specific datatypes for specific variables So my question is WHY CAN'T WE REPLACE int, double, string, char(DATATYPE) WITH var(datatype)
4 Réponses
+ 3
Because each datatype has its own limitations, allowed operations and methods. So the compiler keeps track of datatypes and ensures that the developer doesn't do something stupid, like divide a string with a float ;)
+ 2
var keyword means that you force the compiler to use Type Inference, meaning to determine the datatype automatically, based on the value assignment. But that particular variable will always keep the same datatype.
https://www.c-sharpcorner.com/UploadFile/mahesh/type-inference-in-C-Sharp/
+ 1
I mean why programmers have to go through the trouble of creating specific variables and again converting them? Like we convert int
Convert. ToInt32()
+ 1
Lol thanks a lot