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)

8th Jan 2020, 4:00 AM
Sainath Dora
4 ответов
+ 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 ;)
8th Jan 2020, 4:24 AM
Tibor Santa
Tibor Santa - avatar
+ 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/
8th Jan 2020, 4:14 AM
Tibor Santa
Tibor Santa - avatar
+ 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()
8th Jan 2020, 4:21 AM
Sainath Dora
+ 1
Lol thanks a lot
8th Jan 2020, 12:01 PM
Sainath Dora