-
Key Features and
Create a new project in Visual Studio 2022 - Naming Standards & Comments
- Data Types
- Variables and Constant Variable
- Conditional Statement
- Switch Conditional Statement
- Arithmetic, Comparison, Assignment and Logical Operators
- For, While and Do While Loops
- Importance of Break and Continue Keywords
- Strings and Important String Methods
- Single Dimensional Array
- Multi Dimensional Array
- Methods and Method Overloading
- Math Class and Functions
- Casting and Type Conversions
- Class and Objects
- Constructor, Parameter less and Parameterized Constructor
- Single, Multi level and Hierarchical Inheritance
- Compile Time Polymorphism, Method and Operator Overloading
- Run-time Polymorphism and Importance of base keyword
- Abstract Class and Method
- Interface and Multiple Inheritance through Interfaces
Agenda
- C# Data Types
- Value Data Types
- Reference Data Types
- Pointer Data Types
C# Data Types
- A data type is a classification of the type of data that a variable or object can hold in computer programming. It is important to use the correct data type for the corresponding variable; to avoid errors, to save time and memory.
- C# supports three categories of 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:
- byte (8 bits, 0 to 255); Example: byte b =10;
- sbyte (8 bits, -128 to 127); Example: sbyte b =-10;
- short (16 bits); Example: short s =-1000;
- Integer (32 bits); Example: int i = -10000;
- long (64 bits); Example: long l =-100000000000L;
- ushort (16 bits, 0 to 65535); Example: ushort s =1000;
- uint (32 bits); Example: uint i = 10000;
- ulong (64 bits); Example: ulong l =100000000000;
ii) Floating Point Types (Numbers with decimal places)
- float (32 bits); Example: float f = 1.23f;
- double (64 bits); Example: double d =123.4567890;
- decimal (128 bits); Example: decimal d =123.456m;
iii) Characters:
- Character (16 bits, used to store a single character. The character must be surrounded by single quotes, like ‘D' or ‘m'); Example: char c =’Z’;
iv) Conditional
- 8) Boolean (1 bit); Example: bool b = true;
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();}}