Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C# DataTypes



Data Types in a programming language describes what type of data a variable can hold. CSharp is a strongly typed language. Therefore every variable and object must have a declared type. The CSharp type system contains three Type categories. They are Value Types, Reference Types and Pointer Types. In CSharp, it is possible to convert a value of one type into a value of another type. The operation of Converting a Value Type to a Reference Type is called Boxing, and the reverse operation is called Unboxing.
When we declare a variable, we have to tell the compiler about what type of data the variable can hold or which data type the variable belongs to.

Syntax

DataType VariableName
  1. DataType: The type of data that the variable can hold
  2. VariableName: the variable we declare to hold the values.

Example

 int count;
  • int: is the data type
  • count: is the variable name

The above example shows declare a variable ‘count’ for holding an integer value.
The following are the commonly using datatypes in C#.

bool

The bool keyword is an alias of System. Boolean. It is used to declare variables to store the Boolean values, true and false. In C#, there is no conversion between the bool type and other types.

  • C# Runtime type : System.Boolean
  • CSharp declaration : bool flag;
  • CSharp Initialization : flag = true;
  • CSharp default initialization value : false

int

int variables are stored signed 32 bit integer values in the range of -2,147,483,648 to +2,147,483,647

  • C# Runtime type : System.Int32
  • CSharp declaration : int count;
  • CSharp Initialization : count = 100;
  • CSharp default initialization value : 0

decimal

The decimal keyword denotes a 128-bit data type.The approximate range and precision for the decimal type are -1.0 X 10-28 to 7.9 X 1028

  • C# Runtime type : System.Decimal
  • CSharp declaration : decimal val;
  • CSharp Initialization : val = 0.12;
  • CSharp default initialization value : 0.0M

string

The string type represents a string of Unicode characters. string variables are stored any number of alphabetic,
numerical, and special characters.

  • C# Runtime type : System.String
  • CSharp declaration : string str;
  • CSharp Initialization : str = “csharp string”;

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More