Using Var - Implicitly Typed Fields - Quick Tip

Using Var - Implicitly Typed Fields - Quick Tip

World of Zero

5 лет назад

740 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@darktip
@darktip - 20.02.2019 16:28

Very useful with foreach loops and LINQ queries. Use it all the time. But in other scenarios it's better to stick to explicit typing.

Ответить
@stropheum
@stropheum - 21.02.2019 03:21

Good video! I would add that it's good practice to only use var when there's a (visually) explicit declaration on the right hand side. For example, doing var myvar = myObscureMethod() makes the return type unnecessarily ambiguous, so in this case strict typing makes more sense, but for something that's unnecessarily verbose it can clean it up quite well, something like var myvar = new SpecificVerboseType() and the type is still visually determinable

Ответить