Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Video series C# Fundamentals: Declaring Variables and Assigning Values Duration - 05

Back to Forum: Tech Off
  • User profile image

    Hi there,

    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?

    just curious,



  • User profile image

    @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.

  • User profile image

    Ah. i see ! Thanks for the reply Smiley

  • User profile image

    There are some languages that do type checking at runtime (JavaScript and Python come to mind), and there is a small performance penalty, but today's computers are more than powerful enough to handle it.

  • User profile image

    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.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.