SlideShare a Scribd company logo
1 of 71
C# 101: Intro to C# Programming
Introduction
• Your Name
• Your day job
• Your last holiday destination?
C# 101
• C# Fundamentals
– Setting up your development environment
– Language Overview
– How C# Works
– Writing your first program
– Built-in Data Types
– Conditionals and Loops
C# 102
• Object-oriented Programming
– Classes and Objects
– Polymorphism, Inheritance and Encapsulation
– Functions and Libraries
C# 103
• Data Structures
– Arrays
– Collections
C# 101: Introduction to C#
Setting up your Development
Environment
Installing Integrated Development Kit
• Download latest VS IDE from
https://www.visualstudio.com/en-
us/downloads/download-visual-studio-vs.aspx
What is an IDE?
• IDE = Integrated Development Environment
• Makes you more productive
• Includes text editor, compiler, debugger,
context- sensitive help, works with different
SDKs
• Visual Studio is the most widely used IDE
Installing Visual Studio
• Download and install the latest Visual Studio
for .Net framework(64 Bit version) from
https://www.microsoft.com/en-
gb/download/details.aspx?id=30653
• To start Visual Studio
– On PC, double-click on Visual Studio
Hands-on Exercise
Visual Studio Setup & Demo
C# 101: Introduction to C#
Language Overview
C# Language Overview
• Object-oriented
• Widely available
• Widely used
C# Versions
• Brief History…
- C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg, was previously
involved with the design of Pascal, Delphi and Visual J++
• Major Version Releases
– C# 1.0 (2002)
– C# 2.0 ( 2005)
– C# 3.0 (2008)
– C# 4.0 (2010)
– C# 5.0 (2012)
– C# 6.0 (2015)
Visual Studio Editions
• Visual Studio Standard Edition
• Visual Studio Enterprise Edition
• Visual Studio Community Edition
• Visual Studio Express Edition
.NET Framework
A programming infrastructure created by Microsoft for building,
deploying, and running applications and services that use .NET
technologies, such as desktop applications and Web services.
The .NET Framework contains three major parts:
the Common Language Runtime.
the Framework Class Library.
ASP.NET.
.NET framework is required to develop and compile programs
Developers must have this installed
C# 101: Introduction to C#
How C# works
How C# Works
C# File Structure
C# 101: Introduction to C#
Writing Your First Program
Hello, World!
Writing Your First C# Program
• Create a new project in your IDE named Csharp101
• Create a HelloWorld class in the src folder inside the Csharp101 project as illustrated
below.
using System;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{ /* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}
Compiling Your First Java Program
• Save the HelloWorld class in the IDE
• This automatically compiles the HelloWorld.cs file into
into a HelloWorld.class file
• Go to the folder you created the csharp101 project on
your hard disk and open the src folder.
• What do you see?
Running Your First C# Program
• Build and Run your program in Visual Studio
by Ctrl+Shift+B / F5
Anatomy of a C# Application
Comments Class Name
Access
modifier
Function/static
method
Arguments
Language Features
Introduction to C#
Built-in Data Types
Built-in Data Types
• Data type are sets of values and operations
defined on those values.
Basic Definitions
• Variable - a name that refers to a value.
• Assignment statement - associates a value
with a variable.
String Data Type
Data Type Attributes
Values sequence of characters
Typical literals “Hello”, “1 “, “*”
Operation Concatenate
Operator +
• Useful for program input and output.
String Data Type
String Data Type
• Meaning of characters depends on context.
String Data Type
Expression Value
“Hi, “ + “Bob” “Hi, Bob”
“1” + “ 2 “ + “ 1” “ 1 2 1”
“1234” + “ + “ + “99” “1234 + 99”
“1234” + “99” “123499”
Hands-on Exercise
Command Line Arguments
Exercise: Command Line Arguments
• Create the C# program below that takes a name as command-line
argument and prints “Hi <name>, How are you?”
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string x;
System.Console.WriteLine("Enter your name");
x = Console.ReadLine();
System.Console.WriteLine("Hi {0} , How are you", x);
Console.ReadKey();
}
}
}
Integer Data Type
Data Type Attributes
Values Integers between -2E31 to +2E31-1
Typical literals 1234, -99 , 99, 0, 1000000
Operation Add subtract multiply divide remainder
Operator + - * / %
• Useful for expressing algorithms.
Integer Data Type
Expression Value Comment
5 + 3 8
5 – 3 2
5 * 3 15
5 / 3 1 no fractional
part
5 % 3 2 remainder
1 / 0 run-time error
3 * 5 - 2 13 * has
precedence
3 + 5 / 2 5 / has
precedence
3 – 5 - 2 -4 left associative
(3-5) - 2 -4 better style
3 – (5-2) 0 unambiguous
Double Data Type
• Useful in scientific applications and floating-
point arithmetic
Data Type Attributes
Values Real numbers specified by the IEEE 754 standard
Typical literals 3.14159 6.022e23 -3.0 2.0 1.41421356237209
Operation Add subtract multiply divide
Operator + - * /
Double Data Type
Expression Value
3.141 + 0.03 3.171
3.141 – 0.03 3.111
6.02e23 / 2 3.01e23
5.0 / 2.0 1.6666666666667
10.0 % 3.141 0.577
1.0 / 0.0 Infinity
Math.sqrt(2.0) 1.4142135623730951
C# Math Library
Methods
Math.sin() Math.cos()
Math.log() Math.exp()
Math.sqrt() Math.pow()
Math.min() Math.max()
Math.abs() Math.PI
http://java.sun.com/javase/6/docs/api/java/lang/Math.html
Hands-on Exercise
Integer Operations
Exercise: Integer Operations
• Create a C# class named IntOps in the C101 project that performs integer
operations on a pair of integers from the command line and prints the results.
Solution: Integer Operations
int num1, num2, sum, prod, quot, rem;
num1 = int.Parse(Console.ReadLine());
num2 = int.Parse(Console.ReadLine());
sum = num1 + num2;
prod = num1 * num2;
quot = num1 / num2;
rem = num1 % num2;
System.Console.WriteLine(" {0} : {1} = {2}", num1, num2,
sum.ToString());
System.Console.WriteLine(" {0} : {1} = {2}", num1, num2,
prod.ToString());
System.Console.WriteLine(" {0} : {1} = {2}", num1, num2,
quot.ToString());
System.Console.WriteLine(" {0} : {1} = {2}", num1, num2,
rem.ToString());
Console.ReadLine();
Boolean Data Type
• Useful to control logic and flow of a program.
Data Type Attributes
Values true or false
Typical literals true false
Operation and or not
Operator && || !
Truth-table of Boolean Operations
a !a a b a && b a || b
true false false false false false
false true false true false true
true false false true
true true true true
Boolean Comparisons
• Take operands of one type and produce an
operand of type boolean.
operation meaning true false
== equals 2 == 2 2 == 3
!= Not equals 3 != 2 2 != 2
< Less than 2 < 13 2 < 2
<= Less than or
equal
2 <= 2 3 <= 2
> Greater than 13 > 2 2 > 13
>= Greater than
or equal
3 >= 2 2 >= 3
Type Conversion
• Convert from one type of data to another.
• Implicit
– no loss of precision
– with strings
• Explicit:
– cast
– method.
Type Conversion Examples
expression Expression type Expression value
“1234” + 99 String “123499”
Int.Parse(“123”) int 123
(int) 2.71828 int 2
Math.round(2.71828) long 3
(int) Math.round(2.71828) int 3
(int) Math.round(3.14159) int 3
11 * 0.3 double 3.3
(int) 11 * 0.3 double 3.3
11 * (int) 0.3 int 0
(int) (11 * 0.3) int 3
Hands-on Exercise
Leap Year Finder
Exercise: Leap Year Finder
• A year is a leap year if it is either divisible by 400
or divisible by 4 but not 100.
• Write a java class named LeapYear in the Java101
project that takes a numeric year as command
line argument and prints true if it’s a leap year
and false if not
Solution: Leap Year Finder
int year = int.Parse(Console.ReadLine());
Boolean isLeapYear;
isLeapYear = (year % 4 == 0) && (year % 100 != 0);
isLeapYear = isLeapYear || (year % 400 == 0);
System.Console.WriteLine("the Year {0} is {1} ",
year.ToString(), isLeapYear.ToString());
Console.ReadLine();
Data Types Summary
• A data type is a set of values and operations on
those values.
– String for text processing
– double, int for mathematical calculation
– boolean for decision making
• Why do we need types?
– Type conversion must be done at some level.
– Compiler can help do it correctly.
– Example: in 1996, Ariane 5 rocket exploded after
takeoff because of bad type conversion.
Introduction to C#
Conditionals and Loops
Conditionals and Loops
• Sequence of statements that are actually
executed in a program.
• Enable us to choreograph control flow.
Conditionals
• The if statement is a common branching structure.
– Evaluate a boolean expression.
• If true, execute some statements.
• If false, execute other statements.
If Statement Example
if (Math.Sqrt(16) < 3)
System.Console.WriteLine("the number is less than 3");
Else
System.Console.WriteLine("the number is greater than 3");
Console.ReadLine();
More If Statement Examples
While Loop
• A common repetition structure.
– Evaluate a boolean expression.
– If true, execute some statements.
– Repeat.
For Loop
• Another common repetition structure.
– Execute initialization statement.
– Evaluate a boolean expression.
• If true, execute some statements.
– And then the increment statement.
– Repeat.
Anatomy of a For Loop
for (int i = 0; i < 5; i++)
{
System.Console.WriteLine("{0}", i);
}
Console.ReadLine();
Hands-on Exercise
Powers of Two
Exercise: Powers of Two
• Create a new C# project in Visual Studio named Pow2
• Write a C# class named PowerOfTwo to print powers of 2 that are
<= 2N where N is a number passed as an argument to the program.
– Increment i from 0 to N.
– Double v each time
Solution: Power of 2
Control Flow Summary
• Sequence of statements that are actually
executed in a program.
• Conditionals and loops enable us to choreograph
the control flow.
Control flow Description Example
Straight line
programs
all statements are executed in the
order given
Conditionals certain statements are executed
depending on the values of certain
variables
If
If-else
Loops certain statements are executed
repeatedly until certain conditions
are met
while
for
do-while
Homework Exercises
Java 101: Introduction to C#
Hands-on Exercise
Array of Days
Exercise: Array of Days
• Create a C# class named DayPrinter that prints
out names of the days in a week from an array
using a for-loop.
Solution: Arrays of Days
string[] daysOfTheWeek = { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" };
for(int i= 0;i < daysOfTheWeek.Length ;i++)
{
System.Console.WriteLine("{0}", daysOfTheWeek[i]);
}
Hands-on Exercise
Print Personal Details
Exercise: Print Personal Details
• Write a program that will print your name and
address to the console, for example:
Alex Johnson
23 Main Street
New York, NY 10001 USA
Further Reading

More Related Content

What's hot

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
C# programming language
C# programming languageC# programming language
C# programming languageswarnapatil
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in JavaAbhilash Nair
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Abou Bakr Ashraf
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
C#.NET
C#.NETC#.NET
C#.NETgurchet
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
introduction to c #
introduction to c #introduction to c #
introduction to c #Sireesh K
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#Zeeshan Ahmad
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Prgramming paradigms
Prgramming paradigmsPrgramming paradigms
Prgramming paradigmsAnirudh Chauhan
 

What's hot (20)

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
C# programming language
C# programming languageC# programming language
C# programming language
 
C# basics
 C# basics C# basics
C# basics
 
C#ppt
C#pptC#ppt
C#ppt
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1
 
Asp net
Asp netAsp net
Asp net
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
C#.NET
C#.NETC#.NET
C#.NET
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Prgramming paradigms
Prgramming paradigmsPrgramming paradigms
Prgramming paradigms
 
C# Loops
C# LoopsC# Loops
C# Loops
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 

Similar to C# 101: Intro to Programming with C#

Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptxVAIBHAVKADAGANCHI
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Dhiviya Rose
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#ANURAG SINGH
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with javaHawkman Academy
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programmingagorolabs
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best PracticesDavid Keener
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptUdhayaKumar175069
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in Cummeafruz
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functionsray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptAlefya1
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chhom Karath
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
 
C#unit4
C#unit4C#unit4
C#unit4raksharao
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdfAnkurSingh656748
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVAMuskanSony
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerAndrey Karpov
 

Similar to C# 101: Intro to Programming with C# (20)

Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Java 101
Java 101Java 101
Java 101
 
Aspdot
AspdotAspdot
Aspdot
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with java
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
C#unit4
C#unit4C#unit4
C#unit4
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
 

More from Hawkman Academy

Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOpsHawkman Academy
 
What is the secret to great Agile leadership?
What is the secret to great Agile leadership?What is the secret to great Agile leadership?
What is the secret to great Agile leadership?Hawkman Academy
 
Agile Retrospectives
Agile RetrospectivesAgile Retrospectives
Agile RetrospectivesHawkman Academy
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSSHawkman Academy
 
Web 101 intro to html
Web 101  intro to htmlWeb 101  intro to html
Web 101 intro to htmlHawkman Academy
 
Intro to software development
Intro to software developmentIntro to software development
Intro to software developmentHawkman Academy
 
Software Testing Overview
Software Testing OverviewSoftware Testing Overview
Software Testing OverviewHawkman Academy
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to AgileHawkman Academy
 
Introduction to Agile & Scrum
Introduction to Agile & ScrumIntroduction to Agile & Scrum
Introduction to Agile & ScrumHawkman Academy
 
Agile Requirements Discovery
Agile Requirements DiscoveryAgile Requirements Discovery
Agile Requirements DiscoveryHawkman Academy
 
Design 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software RequirementsDesign 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software RequirementsHawkman Academy
 

More from Hawkman Academy (11)

Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
What is the secret to great Agile leadership?
What is the secret to great Agile leadership?What is the secret to great Agile leadership?
What is the secret to great Agile leadership?
 
Agile Retrospectives
Agile RetrospectivesAgile Retrospectives
Agile Retrospectives
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSS
 
Web 101 intro to html
Web 101  intro to htmlWeb 101  intro to html
Web 101 intro to html
 
Intro to software development
Intro to software developmentIntro to software development
Intro to software development
 
Software Testing Overview
Software Testing OverviewSoftware Testing Overview
Software Testing Overview
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
 
Introduction to Agile & Scrum
Introduction to Agile & ScrumIntroduction to Agile & Scrum
Introduction to Agile & Scrum
 
Agile Requirements Discovery
Agile Requirements DiscoveryAgile Requirements Discovery
Agile Requirements Discovery
 
Design 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software RequirementsDesign 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software Requirements
 

Recently uploaded

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy LĂłpez
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programación competitivaDiego Iván Oliveros Acosta
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 

Recently uploaded (20)

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 

C# 101: Intro to Programming with C#

  • 1. C# 101: Intro to C# Programming
  • 2. Introduction • Your Name • Your day job • Your last holiday destination?
  • 3. C# 101 • C# Fundamentals – Setting up your development environment – Language Overview – How C# Works – Writing your first program – Built-in Data Types – Conditionals and Loops
  • 4. C# 102 • Object-oriented Programming – Classes and Objects – Polymorphism, Inheritance and Encapsulation – Functions and Libraries
  • 5. C# 103 • Data Structures – Arrays – Collections
  • 6. C# 101: Introduction to C# Setting up your Development Environment
  • 7. Installing Integrated Development Kit • Download latest VS IDE from https://www.visualstudio.com/en- us/downloads/download-visual-studio-vs.aspx
  • 8. What is an IDE? • IDE = Integrated Development Environment • Makes you more productive • Includes text editor, compiler, debugger, context- sensitive help, works with different SDKs • Visual Studio is the most widely used IDE
  • 9. Installing Visual Studio • Download and install the latest Visual Studio for .Net framework(64 Bit version) from https://www.microsoft.com/en- gb/download/details.aspx?id=30653 • To start Visual Studio – On PC, double-click on Visual Studio
  • 11. C# 101: Introduction to C# Language Overview
  • 12. C# Language Overview • Object-oriented • Widely available • Widely used
  • 13. C# Versions • Brief History… - C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg, was previously involved with the design of Pascal, Delphi and Visual J++ • Major Version Releases – C# 1.0 (2002) – C# 2.0 ( 2005) – C# 3.0 (2008) – C# 4.0 (2010) – C# 5.0 (2012) – C# 6.0 (2015)
  • 14. Visual Studio Editions • Visual Studio Standard Edition • Visual Studio Enterprise Edition • Visual Studio Community Edition • Visual Studio Express Edition
  • 15. .NET Framework A programming infrastructure created by Microsoft for building, deploying, and running applications and services that use .NET technologies, such as desktop applications and Web services. The .NET Framework contains three major parts: the Common Language Runtime. the Framework Class Library. ASP.NET. .NET framework is required to develop and compile programs Developers must have this installed
  • 16. C# 101: Introduction to C# How C# works
  • 19. C# 101: Introduction to C# Writing Your First Program
  • 21. Writing Your First C# Program • Create a new project in your IDE named Csharp101 • Create a HelloWorld class in the src folder inside the Csharp101 project as illustrated below. using System; namespace HelloWorldApplication { class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); Console.ReadKey(); } } }
  • 22. Compiling Your First Java Program • Save the HelloWorld class in the IDE • This automatically compiles the HelloWorld.cs file into into a HelloWorld.class file • Go to the folder you created the csharp101 project on your hard disk and open the src folder. • What do you see?
  • 23. Running Your First C# Program • Build and Run your program in Visual Studio by Ctrl+Shift+B / F5
  • 24.
  • 25. Anatomy of a C# Application Comments Class Name Access modifier Function/static method Arguments
  • 28. Built-in Data Types • Data type are sets of values and operations defined on those values.
  • 29. Basic Definitions • Variable - a name that refers to a value. • Assignment statement - associates a value with a variable.
  • 30. String Data Type Data Type Attributes Values sequence of characters Typical literals “Hello”, “1 “, “*” Operation Concatenate Operator + • Useful for program input and output.
  • 32. String Data Type • Meaning of characters depends on context.
  • 33. String Data Type Expression Value “Hi, “ + “Bob” “Hi, Bob” “1” + “ 2 “ + “ 1” “ 1 2 1” “1234” + “ + “ + “99” “1234 + 99” “1234” + “99” “123499”
  • 35. Exercise: Command Line Arguments • Create the C# program below that takes a name as command-line argument and prints “Hi <name>, How are you?” namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string x; System.Console.WriteLine("Enter your name"); x = Console.ReadLine(); System.Console.WriteLine("Hi {0} , How are you", x); Console.ReadKey(); } } }
  • 36. Integer Data Type Data Type Attributes Values Integers between -2E31 to +2E31-1 Typical literals 1234, -99 , 99, 0, 1000000 Operation Add subtract multiply divide remainder Operator + - * / % • Useful for expressing algorithms.
  • 37. Integer Data Type Expression Value Comment 5 + 3 8 5 – 3 2 5 * 3 15 5 / 3 1 no fractional part 5 % 3 2 remainder 1 / 0 run-time error 3 * 5 - 2 13 * has precedence 3 + 5 / 2 5 / has precedence 3 – 5 - 2 -4 left associative (3-5) - 2 -4 better style 3 – (5-2) 0 unambiguous
  • 38. Double Data Type • Useful in scientific applications and floating- point arithmetic Data Type Attributes Values Real numbers specified by the IEEE 754 standard Typical literals 3.14159 6.022e23 -3.0 2.0 1.41421356237209 Operation Add subtract multiply divide Operator + - * /
  • 39. Double Data Type Expression Value 3.141 + 0.03 3.171 3.141 – 0.03 3.111 6.02e23 / 2 3.01e23 5.0 / 2.0 1.6666666666667 10.0 % 3.141 0.577 1.0 / 0.0 Infinity Math.sqrt(2.0) 1.4142135623730951
  • 40. C# Math Library Methods Math.sin() Math.cos() Math.log() Math.exp() Math.sqrt() Math.pow() Math.min() Math.max() Math.abs() Math.PI http://java.sun.com/javase/6/docs/api/java/lang/Math.html
  • 42. Exercise: Integer Operations • Create a C# class named IntOps in the C101 project that performs integer operations on a pair of integers from the command line and prints the results.
  • 43. Solution: Integer Operations int num1, num2, sum, prod, quot, rem; num1 = int.Parse(Console.ReadLine()); num2 = int.Parse(Console.ReadLine()); sum = num1 + num2; prod = num1 * num2; quot = num1 / num2; rem = num1 % num2; System.Console.WriteLine(" {0} : {1} = {2}", num1, num2, sum.ToString()); System.Console.WriteLine(" {0} : {1} = {2}", num1, num2, prod.ToString()); System.Console.WriteLine(" {0} : {1} = {2}", num1, num2, quot.ToString()); System.Console.WriteLine(" {0} : {1} = {2}", num1, num2, rem.ToString()); Console.ReadLine();
  • 44. Boolean Data Type • Useful to control logic and flow of a program. Data Type Attributes Values true or false Typical literals true false Operation and or not Operator && || !
  • 45. Truth-table of Boolean Operations a !a a b a && b a || b true false false false false false false true false true false true true false false true true true true true
  • 46. Boolean Comparisons • Take operands of one type and produce an operand of type boolean. operation meaning true false == equals 2 == 2 2 == 3 != Not equals 3 != 2 2 != 2 < Less than 2 < 13 2 < 2 <= Less than or equal 2 <= 2 3 <= 2 > Greater than 13 > 2 2 > 13 >= Greater than or equal 3 >= 2 2 >= 3
  • 47. Type Conversion • Convert from one type of data to another. • Implicit – no loss of precision – with strings • Explicit: – cast – method.
  • 48. Type Conversion Examples expression Expression type Expression value “1234” + 99 String “123499” Int.Parse(“123”) int 123 (int) 2.71828 int 2 Math.round(2.71828) long 3 (int) Math.round(2.71828) int 3 (int) Math.round(3.14159) int 3 11 * 0.3 double 3.3 (int) 11 * 0.3 double 3.3 11 * (int) 0.3 int 0 (int) (11 * 0.3) int 3
  • 50. Exercise: Leap Year Finder • A year is a leap year if it is either divisible by 400 or divisible by 4 but not 100. • Write a java class named LeapYear in the Java101 project that takes a numeric year as command line argument and prints true if it’s a leap year and false if not
  • 51. Solution: Leap Year Finder int year = int.Parse(Console.ReadLine()); Boolean isLeapYear; isLeapYear = (year % 4 == 0) && (year % 100 != 0); isLeapYear = isLeapYear || (year % 400 == 0); System.Console.WriteLine("the Year {0} is {1} ", year.ToString(), isLeapYear.ToString()); Console.ReadLine();
  • 52. Data Types Summary • A data type is a set of values and operations on those values. – String for text processing – double, int for mathematical calculation – boolean for decision making • Why do we need types? – Type conversion must be done at some level. – Compiler can help do it correctly. – Example: in 1996, Ariane 5 rocket exploded after takeoff because of bad type conversion.
  • 54. Conditionals and Loops • Sequence of statements that are actually executed in a program. • Enable us to choreograph control flow.
  • 55. Conditionals • The if statement is a common branching structure. – Evaluate a boolean expression. • If true, execute some statements. • If false, execute other statements.
  • 56. If Statement Example if (Math.Sqrt(16) < 3) System.Console.WriteLine("the number is less than 3"); Else System.Console.WriteLine("the number is greater than 3"); Console.ReadLine();
  • 57. More If Statement Examples
  • 58. While Loop • A common repetition structure. – Evaluate a boolean expression. – If true, execute some statements. – Repeat.
  • 59. For Loop • Another common repetition structure. – Execute initialization statement. – Evaluate a boolean expression. • If true, execute some statements. – And then the increment statement. – Repeat.
  • 60. Anatomy of a For Loop for (int i = 0; i < 5; i++) { System.Console.WriteLine("{0}", i); } Console.ReadLine();
  • 62. Exercise: Powers of Two • Create a new C# project in Visual Studio named Pow2 • Write a C# class named PowerOfTwo to print powers of 2 that are <= 2N where N is a number passed as an argument to the program. – Increment i from 0 to N. – Double v each time
  • 64. Control Flow Summary • Sequence of statements that are actually executed in a program. • Conditionals and loops enable us to choreograph the control flow. Control flow Description Example Straight line programs all statements are executed in the order given Conditionals certain statements are executed depending on the values of certain variables If If-else Loops certain statements are executed repeatedly until certain conditions are met while for do-while
  • 65. Homework Exercises Java 101: Introduction to C#
  • 67. Exercise: Array of Days • Create a C# class named DayPrinter that prints out names of the days in a week from an array using a for-loop.
  • 68. Solution: Arrays of Days string[] daysOfTheWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; for(int i= 0;i < daysOfTheWeek.Length ;i++) { System.Console.WriteLine("{0}", daysOfTheWeek[i]); }
  • 70. Exercise: Print Personal Details • Write a program that will print your name and address to the console, for example: Alex Johnson 23 Main Street New York, NY 10001 USA