Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert.ToSingle() for float data Type

Tags:

c#

I have used many of the Convert.To..... functions for conversion , but I didn't understand one thing that for every datatype they have provide a Convert.To function but not for float datatype, in order to convert to float you need to use Convert.ToSingle() , why is this so ?

like image 825
Asim Sajjad Avatar asked Jan 22 '23 08:01

Asim Sajjad


1 Answers

Single is the CTS (Common Type System for .NET) type, float is the C# shorthand for it.

Int32 CTS -> int C#
String CTS -> string C#
Double CTS -> double C#
Single CTS -> float C#
Int16 CTS -> short C#
Int64 CTS -> long C#

etc.

The Convert methods are .NET methods and therefore use the CTS names and not the C# shorthands.

like image 190
Anthony Pegram Avatar answered Jan 25 '23 23:01

Anthony Pegram