Do you use "var"?

Last updated by Tiago Araújo [SSW] 9 months ago.See history

TODO: Byrden - needs a new home (category) and a complete rewrite
Old content from Better LINQ on .ASPX pasted below

        

Despite what it looks like, the var keyword is not a throwback to the dark ages where we did not have strongly typed variables. It is just a short hand to save developers from typing out the type of a variable.

IQueryable<Customers> results =
    from c in dbContext.Customers
    where c.CompanyName.StartsWith(companyNameTextbox.Text)
    select c;
customersBindingSource.DataSource = results;

Figure: Bad example - You should just use "var" instead of "IQueryable"

var results =
    from c in dbContext.Customers
    where c.CompanyName.StartsWith(companyNameTextbox.Text)
    select c;
customersBindingSource.DataSource = results;

Figure: Good example - Using "var" to save few keystrokes

We open source. Powered by GitHub