Please note, this is a STATIC archive of website technosmarter.com from July 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
 

C# Data Types


In the previous tutorial, we discussed variable in C# language. We did example there using variable and data types. In this C# tutorial, we are going to discuss data types in C# Programming. First of all, understand the data types.

Data types in C# -


The data types are different type of value format which is used to store the value in a variable .
In simple words -
Variable stored different type of values which are known as data types.

In C# programming, data types categorized into three types.
1. Value Data types.
2. Referenc data types.
3. Pointer data types

Let's discuss C# data types in Deep -

1. C# Value Data types-


In c# programming, Value data types are based on values . We declared variables with values. In C# programming , direct values based data types are categorized in value data types.
We can assign values directly. Some examples are int, char, and float, which stores numbers, alphabets, and floating-point numbers, respectively. When you declare an int type, the system allocates memory to store the value.

In C# programming, the values data types are also categorized into two parts.

I. Predefined Data Types - Integer, Boolean, Float, etc.

II. User defined Data Types - Structure, Enumerations, etc.

If you are learned data types in C programming then these are not to complex.
Let's create an example to get the size of the double data type. Instead of double data type, you will able to get the size of int, float etc using sizeof(type ).

Let's have a look.


using System;

namespace DataTypesApplication {
   
   class Program {

      static void Main(string[] args) {
          Console.WriteLine("Size of duble type: {0}", sizeof(double));
          Console.WriteLine("Size of int type: {0}", sizeof(int));
           Console.WriteLine("Size of float type: {0}", sizeof(float));
         Console.ReadLine();
      }
   }
}


Execute the above example, you will get results as output.
Output -

Size of double type: 8
Size of int type: 4
Size of float type: 4
 

 

Let's discuss another data type in C#.

 

2.C# Reference Types

The reference data types do not contain the actual data stored in a variable, but they contain a reference to the variables.

If the data is changed by one of the variables, the other variable automatically reflects this change in value.


The reference data type is also categorized into two types.

I) Predefined Types - Objects, String.

II) User-defined Types - Classes, Interface.


3. C# Pointer Types-


In C# programming, the pointer is known as a variable. Pointer type variables store the memory address of another type. It works as an indicator and locator that which points value address.

We use & ampersand sign and * asterisk to declare a pointer. In C#, & ampersand is known as address operator and * asterisk is known, indicator operator.

We determine the address of value using & and access the value of an address using * asterisk.

 

How to declare pointer type in C#? 


In C# programming, we declare pointer type using *(asterisk).
Let's have a look.
type* identifier ;

int* x;
float* y;
char* z;
int* pnt;
char* ch;

In this way, we can declare pointer type in C# programming.


Please Share

Recommended Posts:-