P
P
Pragma Games2021-09-20 10:30:42
C++ / C#
Pragma Games, 2021-09-20 10:30:42

Which is faster: var or explicit type declaration?

Which way is faster?
A a = new A();
var a = new A();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-09-20
@PragmaGames

Equally.
var is an instruction to the compiler to determine the type itself, and this does not affect the runtime in any way.
Sometimes it will even be faster, because the variable will be of the most concrete type (and then you won’t have to box anything, and you won’t have to make virtual calls through the base class or interface)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question