ToString vs nameof Performance

Michael Moreno
Nerd For Tech
Published in
1 min readApr 14

--

This is a short post — barely an article. You can read it over your morning coffee or tea and then scroll onward.

I was going through a codebase the other day and I noticed a lot of methods doing effectively the same thing in two different ways:

public static bool PerformSomeCheck_Version_1(string someStringToCheck)
{
return someStringToCheck == Fruits.Pear.ToString();
}

...

public static bool PerformSomeCheck_Version_2(string someStringToCheck)
{
return someStringToCheck == nameof(Fruits.Pear);
}

...

enum Fruits
{
Apple,
Banana…

--

--