Skip to content

Commit

Permalink
Update "use-var" rule.md (#6141)
Browse files Browse the repository at this point in the history
* Update "use-var" rule.md

* Update rule.md

---------

Co-authored-by: Luke Parker [SSW] <[email protected]>
  • Loading branch information
tiagov8 and Hona authored Jul 28, 2023
1 parent 8bc1f2e commit 6373810
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions rules/use-var/rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ authors:
url: https://www.ssw.com.au/people/bryden-oliver
created: 2021-12-13T17:44:06.489Z
guid: edd8d397-3651-47c0-8737-fa38152558d1

---

::: todo
TODO: Byrden - needs a new home (category) and a complete rewrite
Old content from Better LINQ on .ASPX pasted below
Expand All @@ -17,24 +19,24 @@ 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.

```
```csharp
IQueryable<Customers> results =
from c in dbContext.Customers
where c.CompanyName.StartsWith(companyNameTextbox.Text)
select c;
customersBindingSource.DataSource = results;
```
::: bad
Figure: Bad - you should just use "var" instead of "IQueryable"
Figure: Bad example - You should just use "var" instead of "IQueryable"
:::

```
```csharp
var results =
from c in dbContext.Customers
where c.CompanyName.StartsWith(companyNameTextbox.Text)
select c;
customersBindingSource.DataSource = results;
```
::: good
Figure: Good - using "var" to save few keystrokes
:::
Figure: Good example - Using "var" to save few keystrokes
:::

0 comments on commit 6373810

Please sign in to comment.