TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# Single and Double Types

This C# article demonstrates the Single and Double types. These types are known as float and double.

Single, double. Single and Double types are available.

They have no differences from the common types they are aliased to. In C# programming, we often hear about a Double, but less commonly about a Single.

Type information

 float -> Single
double -> Double

Example. First, this program creates an instance of the Single and Double types. It then prints their types to the console window. Then it does the same thing for the float and double types.

FloatDouble

And: This shows us that the Single type is the same as the float type, and the Double type is the same as the (lowercase) double type.

C# program that uses Single and Double

using System;

class Program
{
    static void Main()
    {
	{
	    Single a = 1;
	    Double b = 1;
	    Console.WriteLine(a.GetType());
	    Console.WriteLine(b.GetType());
	}
	{
	    float a = 1;
	    double b = 1;
	    Console.WriteLine(a.GetType());
	    Console.WriteLine(b.GetType());
	}
    }
}

Output

System.Single
System.Double
System.Single
System.Double

Discussion. The Single and Double types are floating-point number representations. They are precisely equivalent to the float and double types. It is more conventional for C-style language programmers to use float than Single.

Tip: Code written with float is less likely to confuse other programmers who might then introduce bugs.

Summary. This article doesn't provide useful examples for Single or Double, but just demonstrates that these types are precisely equivalent to the float and double types. This is aliasing. One type is aliased to another at the language level.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf