Variables

Primitive Data Types in C#

To declare the type of data for the value of a variable. Primitive data types include: int, short, long, byte, float, double, char, and boolean.


Syntax
dataType variableName;

Notes

Integer valued data types include: int (4byte), short (2byte), long (8byte), and byte (1byte).

Floating-point data types include: float (4byte), and double (8byte).

Char is a 16bit character using Unicode encoding.

Boolean is a true or false value.

C# also supports complex data types such as strings and objects. It also allows for user-defined types through class and interface definitions.

Strings in C# are used with the String class, however the data type 'string' acts as an alias for System.String.


Example
int hour = 5; 
float cpuTime = 3.14; 
bool hasStarted = true; 
char yesNo = 'y'; 
System.String message = "Random Data Declarations!"; 
string month = "January";

< Namespace   |   Variable Declaration >

© 2019 SyntaxDB. All Rights Reserved.