SlideShare une entreprise Scribd logo
1  sur  48
CS4443
MODERN PROGRAMMING LANGUAGE – I
Mr. Dilawar
Lecturer,
Computer Science Faculty,
Bakhtar University
Kabul, Afghanistan.
Previous Outline
• The C# language
• The .NET Architecture and .NET Framework
• CLR, MSIL, JITers, FCL, CLS, CTS and GC
• C# compare to C++
• Development Environment
• Console Applications and Windows Form Application
• Working with First Hello World Program in C#
• Understanding namespaces, using keyword, class keyword, main() method
and comments in C#
C# Language Fundamentals
Chapter 2
Chapter Outline
• Basic Data Types and their Mapping to CTS
• Variables, Constants, and Operators
• Working with Flow Control and Conditional Statements
• Type Conversion, String Manipulation and Complex Variable Types
• Arrays in C#
• Foreach loop
Lecture Outline
• Basic Data Types and their Mapping to CTS
• Variables, Constants, and Operators
• Working with Flow Control and Conditional Statements
• Type Conversion, String Manipulation and Complex Variable Types
• Arrays in C#
• Foreach loop
Basic Data Types and their Mapping to CTS
• Data types are implemented based on their classification.
• Value types (implicit data types, structures, and enumeration)
• Reference types (objects, strings, arrays, delegates)
• A data type is a value type if it holds the data within its own memory
allocation.
• A variable of a value type is passed to method by passing an exact copy.
• A reference type contains a pointer to another memory location that holds
the data.
• A variable of a reference type is passed to method by passing only their reference.
Basic Data Types and their Mapping to CTS
• Implicit data types are defined by the language vender.
• Explicit data types are composed or made by using the implicit data
type.
• Implicit data types are complaint with .NET complaint languages and
are mapped to types in the CTS.
• Hence each implicit data type in C# has its corresponding .NET type.
• The implicit data types in C# are given in the next slide.
Basic Data Types and their Mapping to CTS
C# Type .NET Type Size in Bytes Description
byte Byte 1 May contain integers from 0 – 255
sbyte Sbyte 1 Signed byte from -128 to 127
short Int16 2 Ranges from -32768 to +32767
ushort UInt16 2 Unsigned, ranges from 0 to 65535
int Int32 4 Ranges from -2147483648 to +2147483647
uint UInt32 4 Unsigned, ranges from 0 to 4294967295
long Int64 8 -9223372036854775808 to
+9223372036854775808
ulong UInt64 8 Unsigned, ranges from 0 to
18446744073709551615
Basic Data Types and their Mapping to CTS
C# Type .NET Type Size in Bytes Description
float Single 4 Ranges from ±1.5 × 10
− 45 to ±3.4 × 10
− 38
precision. Requires the suffix f ot F.
double Double 8 Ranges from ±5.0 × 10
− 324 to ±1.7 × 10308
with 15-16 digits precision.
bool Boolean 1 Contains either true or false
char Char 2 Contains any single Unicode character enclosed in
single quotation mark such as ‘c’
decimal Decimal 12 Ranges from 1.0 × 10
− 28 to 7.9 × 1028 with 28-
29 digits precision. Requires the suffix ‘m’ or ‘M’
Basic Data Types and their Mapping to CTS
• Implicit data types are represented in language using keywords in C#.
• string is also a keyword in C#.
• Implicit data types – are value types and they are stored on stack.
• A stack is a data structure that store items in FIFO fashion.
• It is an area of memory supported by the processor and its size is determined at the
compile time.
• While user defined types or referenced types are stored using heap.
• A heap consists of memory available to the program at runtime.
• Reference types are allocated using memory available from the heap dynamically.
Variables
• A variable is the name given to a memory location holding a particular
type of data.
• Each variable has a data type and a value.
• In C#, variable are declared as:
<data type> <variable_name>;
• You can initialize the variable as you declare it (on the fly).
• You can also declare/initialize multiple variables of the same type in a single
statement.
Variables
• In C#, like other languages you must declare variables before using
them.
• Definite Assignment – Local variables must be initialized before being
used.
• C# does not assign default values to local variables.
• C# is also a type safe language.
• Values of particular data type can only be stored in their respective data type.
• Can’t store integer values in Boolean data types like we do in C/C++.
Naming Conventions for Variable and
Methods
• Microsoft suggests using Carrel Notation for variables.
• First letter in lowercase.
• Pascal Notation for methods.
• First letter in uppercase.
• Each word after the first word in the name of both variables and
methods should start with a capital letter.
Constants
• Constants are variables whose values, once defined, can not be
changed by the program.
• Constant variables are declared using the CONST keyword like:
const double PI = 3.142;
• Constant variables must be initialized as they are declared.
• It is conventional to use capital letters when naming constant
variables.
Operators
• Symbols used to perform operation on the data.
• Arithmetic operators +, -, *, /, %
• Increment and Decrement ++, --
• Prefix and Postfix notation
• In prefix, the compiler will increment the variable and then will use it.
• In postfix, the compiler will first use and then increment it.
• Arithmetic Assignment Operators S+=, -=, *=, /=, %=
• Relational Operators ==, !=, >, <, >=, <=
• Logical and Bitwise Operators &, |, ^, !, &&, ||
• Other operators <<, >>, ., [], (), ? :
Expressions
• C# contains number of operators for this purpose.
• By combining operators with variables and literal value (together referred as
operands), you can create expressions, which is the building blocks of
computation.
Operator Precedence
Flow Control and Conditional Statements
The if Statement
Flow Control and Conditional Statements
The if…….else….. Statement
Nested if and Nested if-else
Flow Control and Conditional Statements
The switch……..case Statement
Flow Control and Conditional Statements
The for loop Statement
Use of Continue
and Break
Statement.
Flow Control and Conditional Statements
The do……while Loop Statement
Flow Control and Conditional Statements
The while Loop Statement
Flow Control and Conditional Statements
The goto Statement
Type Conversion
• There are two types of type conversion:
• Implicit and Explicit conversion
• Implicit conversion requires no work on your part and no additional
code.
Type Conversion
Type Conversion
• As the name suggests, an explicit conversion occurs when you
explicitly ask the compiler to convert a value from one data type to
another.
• Requires extra code, and format of this code may vary, depending on the
exact conversion method.
Type Conversion
• Before working with explicit conversion, try the code below:
Type Conversion
• To get the code compile, you need to add some code.
• in this context, you have to cast the short variable into a byte (as suggested by
the preceding error string).
• Casting basically means forcing data from one type into another, and
it uses the following simple syntax:
<(destinationType)sourceVar>
Type Conversion
Type Conversion
Type Conversion
• Attempting to fit a value into a variable when that value is too big for
the type of that variable results in an overflow, and this is the
situation you want to check for.
• Two keywords exist for setting what is called the overflow checking
context for an expression: checked and unchecked.
checked (<expressions>)
unchecked (<expressions>)
Type Conversion
Type Conversion
• You can also use
Convert command to
make explicit conversion.
String Manipulation
• Writing strings to console, reading strings from the console, and
concatenating strings using the + operator.
• A string type variable can be treated as a read-only array of char
variables.
• You can access individual characters using syntax like the following:
String Manipulation
• To get a char array you have to use ToCharArray() command of
the array variable.
• Later, you can manipulate it as normal array of characters.
• You can access the number of elements using myString.Length.
String Manipulation
• You can work with other operations like <string.ToUpper()>
and <string.ToLower()> and etc…
• As it not changes the original value so it’s better to assign it into
another variable again.
String Manipulation
• For removing extra spaces for ease of
interpretation so you can use
<string>.Trim() command.
• You can also specify which string to trim from
the string.
• You can work <string>.TrimStart()
and <string>.TrimEnd()
• Spaces from the beginning and end of the string.
• You can use <string>.PadLeft() and
<string>.PadRight().
Complex Variable Types
• Enumeration (often referred to as enum), structs (referred to as
structures) and arrays.
• Enumeration allow the definition of a type that can take one of a
finite set of values that you supply.
• Orientation example – creating enum type called orientation.
• It creates a user-defined type and then it is applied to a variable.
Complex Variable Types
• You can use enum keyword to define
enumeration as given.
• Next, you can declare variable of this
new type.
• You can assign values using the given
syntax.
Complex Variable Types
• structs are data structures
that are composed of several
pieces of data, possibly of
different types.
• You can use struct keyword to
define structure as given.
Arrays
• Situations where you want to store a lot of data, so you have to
declare individual variables as
• Arrays are indexed lists of variables stored in a single array type
variable.
• An array called friendNames that stores the three names (elements) and can
be accessed through number (index) in square brackets, as shown:
Arrays
• Arrays are declared in the following way:
• Arrays can be initialized in two ways:
Arrays
• Alternative ways
foreach Loop
• A foreach loop enables you to address each element in an array
using this simple syntax:
• This loop will cycle through each element, placing it in the variable
<name> in turn, without danger of accessing illegal elements.
• It gives you read-only access to the array contents.
foreach Loop
Summery
• Basic Data Types and their Mapping to CTS
• Variables, Constants, and Operators
• Working with Flow Control and Conditional Statements
• Type Conversion, String Manipulation and Complex Variable Types
• Arrays in C#
• foreach loop
Thank You
For your Patience

Contenu connexe

Tendances

Top schools in gudgao
Top schools in gudgaoTop schools in gudgao
Top schools in gudgaoEdhole.com
 
Top schools in gudgao
Top schools in gudgaoTop schools in gudgao
Top schools in gudgaoEdhole.com
 
10 instruction sets characteristics
10 instruction sets characteristics10 instruction sets characteristics
10 instruction sets characteristicsSher Shah Merkhel
 
11 instruction sets addressing modes
11  instruction sets addressing modes 11  instruction sets addressing modes
11 instruction sets addressing modes dilip kumar
 
Unit 1 Computer organization and Instructions
Unit 1 Computer organization and InstructionsUnit 1 Computer organization and Instructions
Unit 1 Computer organization and InstructionsBalaji Vignesh
 
Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.MITS Gwalior
 
Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)Sudarshan Mondal
 
Advanced computer architecture unit 5
Advanced computer architecture  unit 5Advanced computer architecture  unit 5
Advanced computer architecture unit 5Kunal Bangar
 
parallel language and compiler
parallel language and compilerparallel language and compiler
parallel language and compilerVignesh Tamil
 
Parallel architecture-programming
Parallel architecture-programmingParallel architecture-programming
Parallel architecture-programmingShaveta Banda
 
12 processor structure and function
12 processor structure and function12 processor structure and function
12 processor structure and functiondilip kumar
 
18 parallel processing
18 parallel processing18 parallel processing
18 parallel processingdilip kumar
 
02 computer evolution and performance
02 computer evolution and performance02 computer evolution and performance
02 computer evolution and performancedilip kumar
 
Computer Architecture and organization ppt.
Computer Architecture and organization ppt.Computer Architecture and organization ppt.
Computer Architecture and organization ppt.mali yogesh kumar
 
Multicore and shared multi processor
Multicore and shared multi processorMulticore and shared multi processor
Multicore and shared multi processorSou Jana
 
Parallel Programing Model
Parallel Programing ModelParallel Programing Model
Parallel Programing ModelAdlin Jeena
 

Tendances (20)

Top schools in gudgao
Top schools in gudgaoTop schools in gudgao
Top schools in gudgao
 
Top schools in gudgao
Top schools in gudgaoTop schools in gudgao
Top schools in gudgao
 
10 instruction sets characteristics
10 instruction sets characteristics10 instruction sets characteristics
10 instruction sets characteristics
 
11 instruction sets addressing modes
11  instruction sets addressing modes 11  instruction sets addressing modes
11 instruction sets addressing modes
 
system-software-tools
system-software-toolssystem-software-tools
system-software-tools
 
13 risc
13 risc13 risc
13 risc
 
Unit 1 Computer organization and Instructions
Unit 1 Computer organization and InstructionsUnit 1 Computer organization and Instructions
Unit 1 Computer organization and Instructions
 
Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.
 
Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)Lec 2 (parallel design and programming)
Lec 2 (parallel design and programming)
 
Advanced computer architecture unit 5
Advanced computer architecture  unit 5Advanced computer architecture  unit 5
Advanced computer architecture unit 5
 
parallel language and compiler
parallel language and compilerparallel language and compiler
parallel language and compiler
 
CO Module 5
CO Module 5CO Module 5
CO Module 5
 
System software
System softwareSystem software
System software
 
Parallel architecture-programming
Parallel architecture-programmingParallel architecture-programming
Parallel architecture-programming
 
12 processor structure and function
12 processor structure and function12 processor structure and function
12 processor structure and function
 
18 parallel processing
18 parallel processing18 parallel processing
18 parallel processing
 
02 computer evolution and performance
02 computer evolution and performance02 computer evolution and performance
02 computer evolution and performance
 
Computer Architecture and organization ppt.
Computer Architecture and organization ppt.Computer Architecture and organization ppt.
Computer Architecture and organization ppt.
 
Multicore and shared multi processor
Multicore and shared multi processorMulticore and shared multi processor
Multicore and shared multi processor
 
Parallel Programing Model
Parallel Programing ModelParallel Programing Model
Parallel Programing Model
 

En vedette

CS7330 - Electronic Commerce - lecture (3)
CS7330 - Electronic Commerce - lecture (3)CS7330 - Electronic Commerce - lecture (3)
CS7330 - Electronic Commerce - lecture (3)Dilawar Khan
 
CS7330 - Electronic Commerce - lecture (1)
CS7330 - Electronic Commerce - lecture (1)CS7330 - Electronic Commerce - lecture (1)
CS7330 - Electronic Commerce - lecture (1)Dilawar Khan
 
CS7330 - Electronic Commerce - lecture (2)
CS7330 - Electronic Commerce - lecture (2)CS7330 - Electronic Commerce - lecture (2)
CS7330 - Electronic Commerce - lecture (2)Dilawar Khan
 
CS3270 - DATABASE SYSTEM - Lecture (1)
CS3270 - DATABASE SYSTEM -  Lecture (1)CS3270 - DATABASE SYSTEM -  Lecture (1)
CS3270 - DATABASE SYSTEM - Lecture (1)Dilawar Khan
 
CS7330 Electronic Commerce Course Outline
CS7330 Electronic Commerce Course OutlineCS7330 Electronic Commerce Course Outline
CS7330 Electronic Commerce Course OutlineDilawar Khan
 
EE5440 – Computer Architecture Course Outline
EE5440 – Computer Architecture Course OutlineEE5440 – Computer Architecture Course Outline
EE5440 – Computer Architecture Course OutlineDilawar Khan
 
Sequenciação do genoma Humano
Sequenciação do genoma HumanoSequenciação do genoma Humano
Sequenciação do genoma HumanoCarolina Cruz
 
Hidrocarburos aromaticos (quimica)
Hidrocarburos aromaticos (quimica)Hidrocarburos aromaticos (quimica)
Hidrocarburos aromaticos (quimica)banco pichincha
 
KOLOSY za rok 2016 - Program
KOLOSY za rok 2016 - ProgramKOLOSY za rok 2016 - Program
KOLOSY za rok 2016 - ProgramRadioGdansk
 
Wouter Groot - Medialab Amsterdam
Wouter Groot - Medialab AmsterdamWouter Groot - Medialab Amsterdam
Wouter Groot - Medialab AmsterdamMedia Perspectives
 
Cuestionario matematicas
Cuestionario matematicasCuestionario matematicas
Cuestionario matematicasvaspher
 

En vedette (16)

CS7330 - Electronic Commerce - lecture (3)
CS7330 - Electronic Commerce - lecture (3)CS7330 - Electronic Commerce - lecture (3)
CS7330 - Electronic Commerce - lecture (3)
 
CS7330 - Electronic Commerce - lecture (1)
CS7330 - Electronic Commerce - lecture (1)CS7330 - Electronic Commerce - lecture (1)
CS7330 - Electronic Commerce - lecture (1)
 
CS7330 - Electronic Commerce - lecture (2)
CS7330 - Electronic Commerce - lecture (2)CS7330 - Electronic Commerce - lecture (2)
CS7330 - Electronic Commerce - lecture (2)
 
CS3270 - DATABASE SYSTEM - Lecture (1)
CS3270 - DATABASE SYSTEM -  Lecture (1)CS3270 - DATABASE SYSTEM -  Lecture (1)
CS3270 - DATABASE SYSTEM - Lecture (1)
 
CS7330 Electronic Commerce Course Outline
CS7330 Electronic Commerce Course OutlineCS7330 Electronic Commerce Course Outline
CS7330 Electronic Commerce Course Outline
 
EE5440 – Computer Architecture Course Outline
EE5440 – Computer Architecture Course OutlineEE5440 – Computer Architecture Course Outline
EE5440 – Computer Architecture Course Outline
 
Sequenciação do genoma Humano
Sequenciação do genoma HumanoSequenciação do genoma Humano
Sequenciação do genoma Humano
 
Hidrocarburos aromaticos (quimica)
Hidrocarburos aromaticos (quimica)Hidrocarburos aromaticos (quimica)
Hidrocarburos aromaticos (quimica)
 
KOLOSY za rok 2016 - Program
KOLOSY za rok 2016 - ProgramKOLOSY za rok 2016 - Program
KOLOSY za rok 2016 - Program
 
20170304教學聯繫
20170304教學聯繫20170304教學聯繫
20170304教學聯繫
 
Johan Oomen Beeld en Geluid
Johan Oomen   Beeld en GeluidJohan Oomen   Beeld en Geluid
Johan Oomen Beeld en Geluid
 
Wouter Groot - Medialab Amsterdam
Wouter Groot - Medialab AmsterdamWouter Groot - Medialab Amsterdam
Wouter Groot - Medialab Amsterdam
 
Cuestionario matematicas
Cuestionario matematicasCuestionario matematicas
Cuestionario matematicas
 
The Eye and its function
The Eye and its functionThe Eye and its function
The Eye and its function
 
Dm1
Dm1Dm1
Dm1
 
Math task 3
Math task 3Math task 3
Math task 3
 

Similaire à C# Modern Programming Language Fundamentals

Similaire à C# Modern Programming Language Fundamentals (20)

Lecture 2
Lecture 2Lecture 2
Lecture 2
 
lec 2.pptx
lec 2.pptxlec 2.pptx
lec 2.pptx
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
C language
C languageC language
C language
 
Data Handling
Data HandlingData Handling
Data Handling
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Data structure
Data structureData structure
Data structure
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
C#
C#C#
C#
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Aspdot
AspdotAspdot
Aspdot
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
Csharp
CsharpCsharp
Csharp
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
 

Dernier

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 

Dernier (20)

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 

C# Modern Programming Language Fundamentals

  • 1. CS4443 MODERN PROGRAMMING LANGUAGE – I Mr. Dilawar Lecturer, Computer Science Faculty, Bakhtar University Kabul, Afghanistan.
  • 2. Previous Outline • The C# language • The .NET Architecture and .NET Framework • CLR, MSIL, JITers, FCL, CLS, CTS and GC • C# compare to C++ • Development Environment • Console Applications and Windows Form Application • Working with First Hello World Program in C# • Understanding namespaces, using keyword, class keyword, main() method and comments in C#
  • 4. Chapter Outline • Basic Data Types and their Mapping to CTS • Variables, Constants, and Operators • Working with Flow Control and Conditional Statements • Type Conversion, String Manipulation and Complex Variable Types • Arrays in C# • Foreach loop
  • 5. Lecture Outline • Basic Data Types and their Mapping to CTS • Variables, Constants, and Operators • Working with Flow Control and Conditional Statements • Type Conversion, String Manipulation and Complex Variable Types • Arrays in C# • Foreach loop
  • 6. Basic Data Types and their Mapping to CTS • Data types are implemented based on their classification. • Value types (implicit data types, structures, and enumeration) • Reference types (objects, strings, arrays, delegates) • A data type is a value type if it holds the data within its own memory allocation. • A variable of a value type is passed to method by passing an exact copy. • A reference type contains a pointer to another memory location that holds the data. • A variable of a reference type is passed to method by passing only their reference.
  • 7. Basic Data Types and their Mapping to CTS • Implicit data types are defined by the language vender. • Explicit data types are composed or made by using the implicit data type. • Implicit data types are complaint with .NET complaint languages and are mapped to types in the CTS. • Hence each implicit data type in C# has its corresponding .NET type. • The implicit data types in C# are given in the next slide.
  • 8. Basic Data Types and their Mapping to CTS C# Type .NET Type Size in Bytes Description byte Byte 1 May contain integers from 0 – 255 sbyte Sbyte 1 Signed byte from -128 to 127 short Int16 2 Ranges from -32768 to +32767 ushort UInt16 2 Unsigned, ranges from 0 to 65535 int Int32 4 Ranges from -2147483648 to +2147483647 uint UInt32 4 Unsigned, ranges from 0 to 4294967295 long Int64 8 -9223372036854775808 to +9223372036854775808 ulong UInt64 8 Unsigned, ranges from 0 to 18446744073709551615
  • 9. Basic Data Types and their Mapping to CTS C# Type .NET Type Size in Bytes Description float Single 4 Ranges from ±1.5 × 10 − 45 to ±3.4 × 10 − 38 precision. Requires the suffix f ot F. double Double 8 Ranges from ±5.0 × 10 − 324 to ±1.7 × 10308 with 15-16 digits precision. bool Boolean 1 Contains either true or false char Char 2 Contains any single Unicode character enclosed in single quotation mark such as ‘c’ decimal Decimal 12 Ranges from 1.0 × 10 − 28 to 7.9 × 1028 with 28- 29 digits precision. Requires the suffix ‘m’ or ‘M’
  • 10. Basic Data Types and their Mapping to CTS • Implicit data types are represented in language using keywords in C#. • string is also a keyword in C#. • Implicit data types – are value types and they are stored on stack. • A stack is a data structure that store items in FIFO fashion. • It is an area of memory supported by the processor and its size is determined at the compile time. • While user defined types or referenced types are stored using heap. • A heap consists of memory available to the program at runtime. • Reference types are allocated using memory available from the heap dynamically.
  • 11. Variables • A variable is the name given to a memory location holding a particular type of data. • Each variable has a data type and a value. • In C#, variable are declared as: <data type> <variable_name>; • You can initialize the variable as you declare it (on the fly). • You can also declare/initialize multiple variables of the same type in a single statement.
  • 12. Variables • In C#, like other languages you must declare variables before using them. • Definite Assignment – Local variables must be initialized before being used. • C# does not assign default values to local variables. • C# is also a type safe language. • Values of particular data type can only be stored in their respective data type. • Can’t store integer values in Boolean data types like we do in C/C++.
  • 13. Naming Conventions for Variable and Methods • Microsoft suggests using Carrel Notation for variables. • First letter in lowercase. • Pascal Notation for methods. • First letter in uppercase. • Each word after the first word in the name of both variables and methods should start with a capital letter.
  • 14. Constants • Constants are variables whose values, once defined, can not be changed by the program. • Constant variables are declared using the CONST keyword like: const double PI = 3.142; • Constant variables must be initialized as they are declared. • It is conventional to use capital letters when naming constant variables.
  • 15. Operators • Symbols used to perform operation on the data. • Arithmetic operators +, -, *, /, % • Increment and Decrement ++, -- • Prefix and Postfix notation • In prefix, the compiler will increment the variable and then will use it. • In postfix, the compiler will first use and then increment it. • Arithmetic Assignment Operators S+=, -=, *=, /=, %= • Relational Operators ==, !=, >, <, >=, <= • Logical and Bitwise Operators &, |, ^, !, &&, || • Other operators <<, >>, ., [], (), ? :
  • 16. Expressions • C# contains number of operators for this purpose. • By combining operators with variables and literal value (together referred as operands), you can create expressions, which is the building blocks of computation.
  • 18. Flow Control and Conditional Statements The if Statement
  • 19. Flow Control and Conditional Statements The if…….else….. Statement Nested if and Nested if-else
  • 20. Flow Control and Conditional Statements The switch……..case Statement
  • 21. Flow Control and Conditional Statements The for loop Statement Use of Continue and Break Statement.
  • 22. Flow Control and Conditional Statements The do……while Loop Statement
  • 23. Flow Control and Conditional Statements The while Loop Statement
  • 24. Flow Control and Conditional Statements The goto Statement
  • 25. Type Conversion • There are two types of type conversion: • Implicit and Explicit conversion • Implicit conversion requires no work on your part and no additional code.
  • 27. Type Conversion • As the name suggests, an explicit conversion occurs when you explicitly ask the compiler to convert a value from one data type to another. • Requires extra code, and format of this code may vary, depending on the exact conversion method.
  • 28. Type Conversion • Before working with explicit conversion, try the code below:
  • 29. Type Conversion • To get the code compile, you need to add some code. • in this context, you have to cast the short variable into a byte (as suggested by the preceding error string). • Casting basically means forcing data from one type into another, and it uses the following simple syntax: <(destinationType)sourceVar>
  • 32. Type Conversion • Attempting to fit a value into a variable when that value is too big for the type of that variable results in an overflow, and this is the situation you want to check for. • Two keywords exist for setting what is called the overflow checking context for an expression: checked and unchecked. checked (<expressions>) unchecked (<expressions>)
  • 34. Type Conversion • You can also use Convert command to make explicit conversion.
  • 35. String Manipulation • Writing strings to console, reading strings from the console, and concatenating strings using the + operator. • A string type variable can be treated as a read-only array of char variables. • You can access individual characters using syntax like the following:
  • 36. String Manipulation • To get a char array you have to use ToCharArray() command of the array variable. • Later, you can manipulate it as normal array of characters. • You can access the number of elements using myString.Length.
  • 37. String Manipulation • You can work with other operations like <string.ToUpper()> and <string.ToLower()> and etc… • As it not changes the original value so it’s better to assign it into another variable again.
  • 38. String Manipulation • For removing extra spaces for ease of interpretation so you can use <string>.Trim() command. • You can also specify which string to trim from the string. • You can work <string>.TrimStart() and <string>.TrimEnd() • Spaces from the beginning and end of the string. • You can use <string>.PadLeft() and <string>.PadRight().
  • 39. Complex Variable Types • Enumeration (often referred to as enum), structs (referred to as structures) and arrays. • Enumeration allow the definition of a type that can take one of a finite set of values that you supply. • Orientation example – creating enum type called orientation. • It creates a user-defined type and then it is applied to a variable.
  • 40. Complex Variable Types • You can use enum keyword to define enumeration as given. • Next, you can declare variable of this new type. • You can assign values using the given syntax.
  • 41. Complex Variable Types • structs are data structures that are composed of several pieces of data, possibly of different types. • You can use struct keyword to define structure as given.
  • 42. Arrays • Situations where you want to store a lot of data, so you have to declare individual variables as • Arrays are indexed lists of variables stored in a single array type variable. • An array called friendNames that stores the three names (elements) and can be accessed through number (index) in square brackets, as shown:
  • 43. Arrays • Arrays are declared in the following way: • Arrays can be initialized in two ways:
  • 45. foreach Loop • A foreach loop enables you to address each element in an array using this simple syntax: • This loop will cycle through each element, placing it in the variable <name> in turn, without danger of accessing illegal elements. • It gives you read-only access to the array contents.
  • 47. Summery • Basic Data Types and their Mapping to CTS • Variables, Constants, and Operators • Working with Flow Control and Conditional Statements • Type Conversion, String Manipulation and Complex Variable Types • Arrays in C# • foreach loop
  • 48. Thank You For your Patience

Notes de l'éditeur

  1. They can classified according to whether a variable of particular type stores its own data or a pointer to the data. Namespaces, modules, events, properties and procedures, Variables, constants, and fields.
  2. The GC searches for non-referenced data in heap during the execution of program and returns that space to OS.
  3. &, |, ^ (XOR -- not both true or false) are rarely used in usual programming practice. ! Operator is used to negate a Boolean or bitwise expression. Unary, Binary, Ternary
  4. Switch takes less time as compare to several if-else. You can use either string or integer. The expression must be constant. Illegal to use variable after case. A colon is used after the case statement and not a semicolon. You can use multiple statements under single case and default statements. Brackets are not used. C# does not allow fall-through. Without break not allowed. Position of default is not important.
  5. Loops are used for iteration purposes (doing task multiple times until the termination condition is met).
  6. Loops are used for iteration purposes (doing task multiple times until the termination condition is met).
  7. Loops are used for iteration purposes (doing task multiple times until the termination condition is met).
  8. Loops are used for iteration purposes (doing task multiple times until the termination condition is met).
  9. Bool and string have no implicit conversion.
  10. Any type A whose range of possible values completely fits inside the range of possible values of type B can be implicitly converted into that type.
  11. Attempting to fit a value into a variable when that value is too big for the type of that variable results in an overflow, and this is the situation you want to check for.
  12. With this code execution, it will crash with the error message. It can be configured using windows as well.
  13. myString = myString.PadLeft(10, ‘-’); Write a program to split the text. Write a console application that accepts a string from the user and outputs a string with the characters in reverse order. Write a console application that accepts a string and replaces all occurrences of the string no with yes. Write a console application that places double quotes around each word in a string.
  14. Array entries are often referred to as elements.
  15. Friends.length
  16. Friends.length