user4390607
user4390607

Reputation: 11

What's the difference between Single.TryParse and float.TryParse in C#?

What's the difference between Single.TryParse and float.TryParse in C#?

float a, b;
float.TryParse("0.01", out a);
Single.TryParse("0.02", out b);

Upvotes: 1

Views: 762

Answers (3)

Guffa
Guffa

Reputation: 700630

It's the same method.

The only difference is that the float keyword is an alias for the System.Single type, so you can use it without having a using System; at the top of the file.

The exact equivalent would be:

global::System.Single.TryParse("0.02", out b);

as that would work exactly as the float version regardless what you have included or defined.

Upvotes: 5

Sievajet
Sievajet

Reputation: 3523

The use of float in C# seems to be a throwback to its C/C++ heritage. float still maps to the System.Single type in C#, so the keyword just exists for convenience. You could just as well declare the variable as Single

Upvotes: 1

John
John

Reputation: 3702

There is none. Single is the wrapper class for a float.

Upvotes: 0

Related Questions