Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "use-var" rule.md #6141

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
:::
Loading