Skip to content

Commit cd4025c

Browse files
SimpleSamplesBillWagner
authored andcommitted
Update var.md (#4848)
In example 2 var is not required, its use makes the code more convenient. Without var a class could be created for the results. I will try to make a change to the comments in the example but I am not sure I can figure that out.
1 parent 151efbb commit cd4025c

File tree

1 file changed

+1
-1
lines changed
  • docs/csharp/language-reference/keywords

1 file changed

+1
-1
lines changed

docs/csharp/language-reference/keywords/var.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int i = 10; //explicitly typed
2626
For more information, see [Implicitly Typed Local Variables](../../../csharp/programming-guide/classes-and-structs/implicitly-typed-local-variables.md) and [Type Relationships in LINQ Query Operations](../../../csharp/programming-guide/concepts/linq/type-relationships-in-linq-query-operations.md).
2727

2828
## Example
29-
The following example shows two query expressions. In the first expression, the use of `var` is permitted but is not required, because the type of the query result can be stated explicitly as an `IEnumerable<string>`. However, in the second expression, `var` must be used because the result is a collection of anonymous types, and the name of that type is not accessible except to the compiler itself. Note that in Example #2, the `foreach` iteration variable `item` must also be implicitly typed.
29+
The following example shows two query expressions. In the first expression, the use of `var` is permitted but is not required, because the type of the query result can be stated explicitly as an `IEnumerable<string>`. However, in the second expression, `var` allows the result to be a collection of anonymous types, and the name of that type is not accessible except to the compiler itself. Use of `var` eliminates the requirement to create a new class for the result. Note that in Example #2, the `foreach` iteration variable `item` must also be implicitly typed.
3030

3131
[!code-csharp[csrefKeywordsTypes#18](../../../csharp/language-reference/keywords/codesnippet/CSharp/var_1.cs)]
3232

0 commit comments

Comments
 (0)