I started learning c# and found Bob Tabors c# Fundamental series which i think is great. props to bob and a very big thank you.
Anyways i have a question regarding something he says in ep 5 around 11:00 and further.
he explains what var's are and what they do. which is basically letting the pc figure out what kind of variable i write down on that line.
My question is, if we were to write everything with var's would that eventually strain the pc and hog alot of memory? since it has to figure out what the variable is? as to writing string, or int etc etc?
@udRising: No. The C# var keyword is resolved to a type at compile time, so there is no difference between the runtime speed of
var i = 1;
int i = 1;
Note that putting var everywhere can adversely affect the readability of your code, but it will never affect the speed of your program.
Ah. i see ! Thanks for the reply
Note that in some case you may have to explicitly cast a "var" variable to some type or the runtime will fail to find out which method / operator to use.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.