📜 ⬆️ ⬇️

C # vs R #: use var instead of explicit type



In my work with the wonderful addition of ReSharper in Visual Studio, I was constantly confronted with the proposal instead of explicitly declaring the type of variables to use type declarations implicitly using var . At first I was somewhat surprised, but I did not particularly notice. But after a while, such proposals were already straining and I decided to figure out what the essence of such optimization was.

The answer was found in the blog of the creators of R # at this address . On the cut, my translation of the article by Ilya Ryzhenkov (Ilya Ryzhenkov).


')
So, Ilya cites the following arguments in favor of the widespread use of “var”:

Here is an explanation. I would like to give one more comment on this article. Alexander writes that Microsoft does not recommend using var anywhere except in the case of anonymous types. To which Ilya answers simply: “Yeah, Microsoft often tries to make things„ safer “. I don’t agree with them here. ” I think the translation is superfluous here.

As the public thinks, are Illya’s arguments justified, and therefore ReSharper is making universal use of var instead of an explicit type indication? For me personally, the arguments presented in the article seemed weighty and even correct. Who thinks like?

Source: https://habr.com/ru/post/39231/


All Articles