C# Data Types - c# - c# tutorial - c# net



What is data type in C# and its types ?

  • In data types, a programming language describes that what type of data a variable can hold. C# is a strongly typed language, therefore every variable and object must have a declared type. The C# type system contains three Type categories. They are
    • Value Types,
    • Reference Types and
    • Pointer Types.
 definition of csharp data type definition
  • In C#, it is possible to convert a value of one type into a value of another type.

Syntax

DataType VariableName
click below button to copy the code. By - c# tutorial - team

Syntax Explanation

  • Here DataType is specifying to type of data that the variable can hold.
  • In VariableName, the variable we declare for hold the values.

Value Types:

  • Value type variables can be assigned to value directly. They arederived from the class System.ValueType.
  • The value types directly contain data.
  • c# value type vs reference type :

    learn csharp - csharp tutorial - c# value type vs reference type  - c# examples -  c# programs
  • These are some examples int, char, and float.
  • int data typesstores numbers, char data type stores alphabets, and floating point numbers, respectively. When we declare an int type, the system allocates memory to store the value.
 definition of csharp data type definition

Int datatype:

  • Integers are a subset of the real numbers.
  • int variables are stored signed 32-bit integer values in the range of -2,147,483,648 to +2,147,483,647

Syntax:

int count;
click below button to copy the code. By - c# tutorial - team

Float Datatype:

  • Floating point numbers represent real numbers.
  • Real numbers measure continuous quantities, like weight, height, or speed.
  • In C# we have three floating point types: float, double, and decimal.

Syntax:

float count;
click below button to copy the code. By - c# tutorial - team
Related Tags: kurs c# , c# programmieren , tutorial c# visual studio , learn programming with c# , c# kurs online , the best way to learn c# , c# tutorial for complete beginners from scratch , tuto c# , manual c#

Reference Type

  • The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.
  • In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location.
  • If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value.
  • Example of built-in reference types are: object, dynamic, and string.

Char Datatype:

  • The char keyword is used to declare an instance of the System.Char structure that the .NET Framework uses to represent a Unicode character.
  • The char rage is 16-bit numeric (ordinal) value.

c# type conversion :

  • Implicit type conversion
    • The conversion is happening automatically no need to specify,
    • Changes int data type into a double
    • No implicit conversion from double to int
  • Explicit type coercion
  • The conversion is happening manually, We need to specify, how the conversion we want.
  • Cast - (type) expression
  •  int value1 = 0,	
    	 anotherNumber = 75;
    double  value2 = 100.99,
    	        anotherDouble = 100;
    value1 = (int) value2;	    // value1 = 100 
    value2 = (double) anotherNumber;   // value2 = 75.0
    
    click below button to copy the code. By - c# tutorial - team

    c# format specifiers :

    learn csharp - csharp tutorial - c# format specifiers - c# examples -  c# programs
    learn csharp - csharp tutorial - c# format specifiers - c# examples -  c# programs

    c# Custom Numeric Format Specifiers :

    learn csharp - csharp tutorial - c# numerical format specifiers - c# examples -  c# programs
    learn csharp - csharp tutorial - c# numerical format specifiers - c# examples -  c# programs

    c# Formatting Output :

    learn c# - c# tutorial - c# Formatting Output - c# examples -  c# programs


    Related Searches to C# Data Types