Data Types

Agenda

C# Data Types

a) Value Data Types (It will directly store the variable value in memory and it will also accept both signed and unsigned literals):

i) Signed & Unsigned Integral Types:

ii) Floating Point Types (Numbers with decimal places)

iii) Characters:

iv) Conditional

C# Data Types - Contd

b) Reference Data Types (It will contain a memory address of variable value because the reference types won’t store the variable value directly in memory): Reference data types in C# are Class, Interface, String and Arrays.

Example: String str = “C# Programming”

c) Pointer Data Types (Known as locator or indicator that points to an address of a value): To get the pointer details there are two symbols ampersand (&) and asterisk (*) available. ampersand (&): It is Known as Address Operator. It is used to determine the address of a
variable.

asterisk (*): It also known as Indirection Operator. It is used to access the value of an address.

Example:

int * a; //pointer to int

char * c; //pointer to char


using System;
using  System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


internal class Program
{
static void Main()
{
byte b = 10;
Console.WriteLine(b);
sbyte sb = -100;
Console.WriteLine(sb);
short s = -20;
Console.WriteLine(s);
// int i = -30;
//Console.WriteLine(i);
ushort us = 40;
Console.WriteLine(us);
uint ui = 50;
Console.WriteLine(ui);
long l = -60000899990;
Console.WriteLine(l);
ulong ul = 789202200222;
Console.WriteLine(ul);
float f = 5.7675f; // for float use 'f' as suffix
Console.WriteLine(f);
double d = 5.76757838;
Console.WriteLine(d);
// for decimal use 'm' as suffix
decimal dec = 334.8m;
Console.WriteLine(dec);

bool b1 = true;
Console.WriteLine(b1);
char c = 'D';
Console.WriteLine(c);
String str = "C# Tutorial";
Console.WriteLine(str);
//Console.WriteLine("First C# Program");
Console.ReadKey();

}}