SlideShare a Scribd company logo
Microsoft .Net
(Introduction to C#)
Rohit Rao
Agenda
• Overview of C#
• Control Structures
• Arrays
• Generics
• Namespace
Overview of C#
• Object Oriented Programming Language
• Derived from C, C++ & Java
Control Structure
• Types
– Decision (Conditional) : Use to control the flow of program. Code runs
only once if certain condition is true.
– Iteration
• Decision
– If, if-else, If-else if
– Switch
• Iteration
– For Loop
– ForEach Loop
– While
– Do While
Decision Statements
• If statements
– If : Code runs once only if condition is true.
– If-Else : It allow us to specify the code that should
run if first statement (If) evaluates to false
– If-Else If-Else : It allow us to select from multiple if
statements.
– The ? : Operator :
• Exp1 ? Exp2 : Exp3
Switch
• It allow us to select from pre-defined set of
choices
• After each choice statement, we will have to use
break keyword
switch (i)
{
case 1:
Console.WriteLine(1);
break;
case 2:
Console.WriteLine(2);
break;
case 3:
Console.WriteLine(3);
break;
default:
Console.WriteLine("Please enter a number between 1 & 3.");
break;
}
Iterations
• It repeats the code in cyclic fashion
• For Loop
– It allow us to repeat the block of code N times
– We can use any decision statement in it
– We can use Continue / Break
int sum = 0;
for (int i = 0; i < 5; i++)
{
sum += i;
}
Console.WriteLine(sum);
For Each Loop
• Used to loop through items in a collection or
array individually (With no indexes)
• The collection or array must use interface
IEnumerable / IEnumerable <T>
• We can not add / remove from the collection
within the loop body
string[] students = { "A", "B", "C" };
foreach (string studentName in students)
{
Console.WriteLine(studentName);
}
While Loop
• Repeat the block of code while a certain
condition remains true.
int sum = 0;i = 0;
while (i < 5)
{
sum += i;
i++;
}
Console.WriteLine(sum);
Do-While Loop
• It tests the condition at the end of the loop Body
• Loop is guaranteed to execute at least once time.
int sum = 0;i = 0;
do
{
sum += i;
i++;
} while (i < 5);
Console.WriteLine(sum);
Continue Keyword
• Allow us to immediately move to next
iteration of a loop body
• It starts the next iteration immediately and
skip the steps below the Continue statement
in loop’s body.
Break Keyword
• It is used to move out from the iteration and it
does not loop any more.
• It skips the code below Break statement.
Array
• string[] arrOfStr = new string[] { "A", "B", "C" };
• string[] arrOfStr = new string[3];
arrOfStr[0] = "A";
arrOfStr[1] = "B";
arrOfStr[2] = "C";
• Passing Array To Method
//Method
public void ReadArray(int[] arr)
{ }
//Call
int[] arrOfInt = { 1, 2, 3 };
ReadArray(arrOfInt);
2D Array
string[,] arr2D= new string[,]
{
{"A", "1"},
{"B", "2"},
{"C", "3"},
{"D", "4"},
};
//Print
Console.WriteLine(arr2D[0, 0]);
int arr2D = new int[3, 3];
---------------------------------------------------------------------------------
Passing 2D array to method :
public void Pass2DArray(int[,] arr2d)
{
// Display value of first element in first row.
Console.WriteLine(arr2d[0, 0]);
}
Generics
• Arrays are strong typed
– No boxing / Unboxing (Adv)
– Fixed Length (DisAdv)
• Array List
– Variable / Flexible length (Adv)
– Lot of Boxing / UnBoxing because they take
objects (DisAdv)
• Generics provides advantages of both of these
collection : Strong Type & Flexible
• It creates Flexible Strong Typed Collection
Generics
• It separates the logic from Data Type, to
increase reusability
String
Boolean
Numeric
Generic compare logic (separate from data
type) for all the data types
-> Is “A” == “B” ?
-> Is bTrue == bFlase ?
-> Is 5 == 5 ?
At runtime attach the data type to the
method.
Generic Method Example
//Generic Method
public static bool Compare<T>(T x, T y)
{
if (x.Equals(y))
return true;
return false;
}
• //Method Call
bool result = Compare(10, 12);
Console.WriteLine(result.ToString());
result = Compare("A", "B");
Console.WriteLine(result.ToString());
result = Compare(true, true);
Console.WriteLine(result.ToString());
Console.ReadLine();
Generic Class Example
public class GenericCompare<T>
{
public bool Comapre(T x, T y)
{
if (x.Equals(y))
return true;
return false;
}
}
//Method call for integers
GenericCompare<int> objGenericCompInt = new GenericCompare<int>();
result = objGenericCompInt.Comapre(10, 12);
Console.WriteLine(result.ToString());
//Method Call for string
GenericCompare<String> objGenericCompString = new GenericCompare<String>();
result = objGenericCompString.Comapre("A", "B");
Console.WriteLine(result.ToString());
Generic Collections
• Generic decoupled datatype from Logic
• In .NET, Microsoft team took .NET collections & applied
generic concepts & created Generic Collections
• We will need to import System.Collections.Generic
Array List - > List (Generic) ---- Index Based
Hash Table - > Dictionary --- Key Value Pair
Stack & Queue - > Stack Generics & Queue Generics ---- Prioritized
Generic Collection (Index Based)
• List of Int
• List Of String
List<String> lstStr = new List<string>();
lstStr.Add("A");
lstStr.Add("B");
lstStr.Remove("A");
Generic Collections (Key Based)
• Dictionary : Generic form of HashTables
Dictionary<int, int> dictInt = new Dictionary<int, int>();
dictInt.Add(1, 1);
dictInt.Add(2, 2);
Dictionary<int, string> dictString = new Dictionary<int, string>();
dictString.Add(1, "A");
dictString.Add(2, "B");
Generic Collection (Stack / Queue)
• Stack
Stack<int> stkInt = new Stack<int>();
stkInt.Push(1);
stkInt.Push(2);
stkInt.Pop();
• Queue
Queue<string> QString = new Queue<string>();
QString.Enqueue("A");
QString.Enqueue("B");
QString.Dequeue();
QString.Dequeue();
Generic Collection (Custom Objects)
• We can attach custom objects to Generic
collections :
Student objStudent = new Student();
objStudent.StudentID = 1;
objStudent.RollNo = 1;
objStudent.StudentName = "A";
List<Student> lstStudent = new List<Student>();
lstStudent.Add(objStudent);
IEnumerable, ICollection, IList, IDictionary
• Interfaces : These all are interfaces, It provides
decoupling.
• Encapsulation : We can control how much
collection access should give to end clients.
• Polymorphism : We can dynamically point to
different collection on runtime.
IEnumerable, ICollection, IList, IDictionary
IEnumerator ICollection
IList or
IDictionary
Only Browse Browse + Count Browse + Count + Add +
Remove elements
IEnumerable, ICollection, IList, IDictionary
static void Main(string[] args)
{
//Fetch Students info
Student objStudent = new Student();
ArrayList arrLstStudents = objStudent.GetStudents();
//Here user can modify the arrLstStudents objects but it may be for browse only
purpose
/*
arrLstStudents.Remove(Object obj);
arrLstStudents.Add(Object obj);
*/
//It would be good if we can give him IEnumerable object instead of ArrayList.
So client will not be able to ad / remove items
IEnumerable studentList = objStudent.GetStudentsIEnumerable();
}
IEnumerable, ICollection, IList, IDictionary
public class Student
{
//Method to get array List
public ArrayList GetStudents()
{
ArrayList arrLstStudents = new ArrayList();
//Logic to fetch Student info & Add in ArrayList object
return arrLstStudents;
}
//Method to get IEnumerable
public IEnumerable GetStudentsIEnumerable()
{
ArrayList arrLstStudents = new ArrayList();
//Logic to fetch Student info & Add in ArrayList object
return CovertToIEnumerable(arrLstStudents);
}
public IEnumerable CovertToIEnumerable(ArrayList arrList)
{
return (IEnumerable) arrList;
}
}
NameSpace
• It helps you to organize your program / code.
• It Provides a way to create globally unique
types.
• It helps in avoiding class name clashes in more
than one set of code.
• The compiler adds a default namespace.
NameSpace Contd…
Ad

More Related Content

What's hot (20)

JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
introduction to javascript
introduction to javascriptintroduction to javascript
introduction to javascript
Kumar
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
Mujtaba Haider
 
Placement and variable 03 (js)
Placement and variable 03 (js)Placement and variable 03 (js)
Placement and variable 03 (js)
AbhishekMondal42
 
Java script
Java scriptJava script
Java script
Abhishek Kesharwani
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScript
Jyothishmathi Institute of Technology and Science Karimnagar
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
Bonny Chacko
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
Raveendra R
 
JS - Basics
JS - BasicsJS - Basics
JS - Basics
John Fischer
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Rangana Sampath
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
Sasidhar Kothuru
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 

Viewers also liked (20)

Programming in c#
Programming in c#Programming in c#
Programming in c#
Shehrevar Davierwala
 
4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I
Rohit Rao
 
3. ADO.NET
3. ADO.NET3. ADO.NET
3. ADO.NET
Rohit Rao
 
Microsoft .Net Framework
Microsoft .Net FrameworkMicrosoft .Net Framework
Microsoft .Net Framework
Rohit Rao
 
4. introduction to Asp.Net MVC - Part II
4. introduction to Asp.Net MVC - Part II4. introduction to Asp.Net MVC - Part II
4. introduction to Asp.Net MVC - Part II
Rohit Rao
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
Intro C# Book
 
08. Numeral Systems
08. Numeral Systems08. Numeral Systems
08. Numeral Systems
Intro C# Book
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
Jm Ramos
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
Intro C# Book
 
C# basics
 C# basics C# basics
C# basics
Dinesh kumar
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
Very basic of asp.net mvc with c#
Very basic of asp.net mvc with c#Very basic of asp.net mvc with c#
Very basic of asp.net mvc with c#
Shreejan Acharya
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
Intro C# Book
 
cuaderno completo
cuaderno completocuaderno completo
cuaderno completo
marco_ng_5IV12
 
Help for Victims: Polish flyer
Help for Victims: Polish flyerHelp for Victims: Polish flyer
Help for Victims: Polish flyer
StopTrafficking
 
Hati2
Hati2Hati2
Hati2
Abyanuddin Salam
 
De kracht van de vernieuwing
De kracht van de vernieuwingDe kracht van de vernieuwing
De kracht van de vernieuwing
Marieke van den Groenendaal
 
Eucaristias semana de mision
Eucaristias semana de misionEucaristias semana de mision
Eucaristias semana de mision
Theotokos2013
 
Ad

Similar to 2. overview of c# (20)

Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
Akash Pandey
 
Java introduction
Java introductionJava introduction
Java introduction
Samsung Electronics Egypt
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
For Beginners - C#
For Beginners - C#For Beginners - C#
For Beginners - C#
Snehal Harawande
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
guest5c8bd1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 
Java tut1
Java tut1Java tut1
Java tut1
Ajmal Khan
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
Abdul Aziz
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
Intro C# Book
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
Hawkman Academy
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
raksharao
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
OpenSource Technologies Pvt. Ltd.
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
Christian Nagel
 
Arrays
ArraysArrays
Arrays
Faisal Aziz
 
Python Introduction controll structures and conprehansion
Python Introduction controll structures and conprehansionPython Introduction controll structures and conprehansion
Python Introduction controll structures and conprehansion
ssuser26ff68
 
Core java
Core javaCore java
Core java
Uday Sharma
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
Bui Kiet
 
Java teaching ppt for the freshers in colleeg.ppt
Java teaching ppt for the freshers in colleeg.pptJava teaching ppt for the freshers in colleeg.ppt
Java teaching ppt for the freshers in colleeg.ppt
vvsofttechsolution
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
QUAID-E-AWAM UNIVERSITY OF ENGINEERING, SCIENCE & TECHNOLOGY, NAWABSHAH, SINDH, PAKISTAN
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
Ad

Recently uploaded (20)

Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 

2. overview of c#

  • 2. Agenda • Overview of C# • Control Structures • Arrays • Generics • Namespace
  • 3. Overview of C# • Object Oriented Programming Language • Derived from C, C++ & Java
  • 4. Control Structure • Types – Decision (Conditional) : Use to control the flow of program. Code runs only once if certain condition is true. – Iteration • Decision – If, if-else, If-else if – Switch • Iteration – For Loop – ForEach Loop – While – Do While
  • 5. Decision Statements • If statements – If : Code runs once only if condition is true. – If-Else : It allow us to specify the code that should run if first statement (If) evaluates to false – If-Else If-Else : It allow us to select from multiple if statements. – The ? : Operator : • Exp1 ? Exp2 : Exp3
  • 6. Switch • It allow us to select from pre-defined set of choices • After each choice statement, we will have to use break keyword switch (i) { case 1: Console.WriteLine(1); break; case 2: Console.WriteLine(2); break; case 3: Console.WriteLine(3); break; default: Console.WriteLine("Please enter a number between 1 & 3."); break; }
  • 7. Iterations • It repeats the code in cyclic fashion • For Loop – It allow us to repeat the block of code N times – We can use any decision statement in it – We can use Continue / Break int sum = 0; for (int i = 0; i < 5; i++) { sum += i; } Console.WriteLine(sum);
  • 8. For Each Loop • Used to loop through items in a collection or array individually (With no indexes) • The collection or array must use interface IEnumerable / IEnumerable <T> • We can not add / remove from the collection within the loop body string[] students = { "A", "B", "C" }; foreach (string studentName in students) { Console.WriteLine(studentName); }
  • 9. While Loop • Repeat the block of code while a certain condition remains true. int sum = 0;i = 0; while (i < 5) { sum += i; i++; } Console.WriteLine(sum);
  • 10. Do-While Loop • It tests the condition at the end of the loop Body • Loop is guaranteed to execute at least once time. int sum = 0;i = 0; do { sum += i; i++; } while (i < 5); Console.WriteLine(sum);
  • 11. Continue Keyword • Allow us to immediately move to next iteration of a loop body • It starts the next iteration immediately and skip the steps below the Continue statement in loop’s body.
  • 12. Break Keyword • It is used to move out from the iteration and it does not loop any more. • It skips the code below Break statement.
  • 13. Array • string[] arrOfStr = new string[] { "A", "B", "C" }; • string[] arrOfStr = new string[3]; arrOfStr[0] = "A"; arrOfStr[1] = "B"; arrOfStr[2] = "C"; • Passing Array To Method //Method public void ReadArray(int[] arr) { } //Call int[] arrOfInt = { 1, 2, 3 }; ReadArray(arrOfInt);
  • 14. 2D Array string[,] arr2D= new string[,] { {"A", "1"}, {"B", "2"}, {"C", "3"}, {"D", "4"}, }; //Print Console.WriteLine(arr2D[0, 0]); int arr2D = new int[3, 3]; --------------------------------------------------------------------------------- Passing 2D array to method : public void Pass2DArray(int[,] arr2d) { // Display value of first element in first row. Console.WriteLine(arr2d[0, 0]); }
  • 15. Generics • Arrays are strong typed – No boxing / Unboxing (Adv) – Fixed Length (DisAdv) • Array List – Variable / Flexible length (Adv) – Lot of Boxing / UnBoxing because they take objects (DisAdv) • Generics provides advantages of both of these collection : Strong Type & Flexible • It creates Flexible Strong Typed Collection
  • 16. Generics • It separates the logic from Data Type, to increase reusability String Boolean Numeric Generic compare logic (separate from data type) for all the data types -> Is “A” == “B” ? -> Is bTrue == bFlase ? -> Is 5 == 5 ? At runtime attach the data type to the method.
  • 17. Generic Method Example //Generic Method public static bool Compare<T>(T x, T y) { if (x.Equals(y)) return true; return false; } • //Method Call bool result = Compare(10, 12); Console.WriteLine(result.ToString()); result = Compare("A", "B"); Console.WriteLine(result.ToString()); result = Compare(true, true); Console.WriteLine(result.ToString()); Console.ReadLine();
  • 18. Generic Class Example public class GenericCompare<T> { public bool Comapre(T x, T y) { if (x.Equals(y)) return true; return false; } } //Method call for integers GenericCompare<int> objGenericCompInt = new GenericCompare<int>(); result = objGenericCompInt.Comapre(10, 12); Console.WriteLine(result.ToString()); //Method Call for string GenericCompare<String> objGenericCompString = new GenericCompare<String>(); result = objGenericCompString.Comapre("A", "B"); Console.WriteLine(result.ToString());
  • 19. Generic Collections • Generic decoupled datatype from Logic • In .NET, Microsoft team took .NET collections & applied generic concepts & created Generic Collections • We will need to import System.Collections.Generic Array List - > List (Generic) ---- Index Based Hash Table - > Dictionary --- Key Value Pair Stack & Queue - > Stack Generics & Queue Generics ---- Prioritized
  • 20. Generic Collection (Index Based) • List of Int • List Of String List<String> lstStr = new List<string>(); lstStr.Add("A"); lstStr.Add("B"); lstStr.Remove("A");
  • 21. Generic Collections (Key Based) • Dictionary : Generic form of HashTables Dictionary<int, int> dictInt = new Dictionary<int, int>(); dictInt.Add(1, 1); dictInt.Add(2, 2); Dictionary<int, string> dictString = new Dictionary<int, string>(); dictString.Add(1, "A"); dictString.Add(2, "B");
  • 22. Generic Collection (Stack / Queue) • Stack Stack<int> stkInt = new Stack<int>(); stkInt.Push(1); stkInt.Push(2); stkInt.Pop(); • Queue Queue<string> QString = new Queue<string>(); QString.Enqueue("A"); QString.Enqueue("B"); QString.Dequeue(); QString.Dequeue();
  • 23. Generic Collection (Custom Objects) • We can attach custom objects to Generic collections : Student objStudent = new Student(); objStudent.StudentID = 1; objStudent.RollNo = 1; objStudent.StudentName = "A"; List<Student> lstStudent = new List<Student>(); lstStudent.Add(objStudent);
  • 24. IEnumerable, ICollection, IList, IDictionary • Interfaces : These all are interfaces, It provides decoupling. • Encapsulation : We can control how much collection access should give to end clients. • Polymorphism : We can dynamically point to different collection on runtime.
  • 25. IEnumerable, ICollection, IList, IDictionary IEnumerator ICollection IList or IDictionary Only Browse Browse + Count Browse + Count + Add + Remove elements
  • 26. IEnumerable, ICollection, IList, IDictionary static void Main(string[] args) { //Fetch Students info Student objStudent = new Student(); ArrayList arrLstStudents = objStudent.GetStudents(); //Here user can modify the arrLstStudents objects but it may be for browse only purpose /* arrLstStudents.Remove(Object obj); arrLstStudents.Add(Object obj); */ //It would be good if we can give him IEnumerable object instead of ArrayList. So client will not be able to ad / remove items IEnumerable studentList = objStudent.GetStudentsIEnumerable(); }
  • 27. IEnumerable, ICollection, IList, IDictionary public class Student { //Method to get array List public ArrayList GetStudents() { ArrayList arrLstStudents = new ArrayList(); //Logic to fetch Student info & Add in ArrayList object return arrLstStudents; } //Method to get IEnumerable public IEnumerable GetStudentsIEnumerable() { ArrayList arrLstStudents = new ArrayList(); //Logic to fetch Student info & Add in ArrayList object return CovertToIEnumerable(arrLstStudents); } public IEnumerable CovertToIEnumerable(ArrayList arrList) { return (IEnumerable) arrList; } }
  • 28. NameSpace • It helps you to organize your program / code. • It Provides a way to create globally unique types. • It helps in avoiding class name clashes in more than one set of code. • The compiler adds a default namespace.