SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
Chapter 4
Literals, variables and Data Types
The smallest, non-reducible, textual elements in a program are referred to as Tokens. A C# program is a
collection of tokens, comments and white spaces. C# include the following five types of tokens:
Keywords, Identifiers, Literals, Operators, Punctuators
Keywords are an essential part of a language definition. They implement specific features of the
language. They are reserved, and cannot be used as identifiers except when they are prefaced by the @
character.
Identifiers are programmer –designed tokens. They are used for naming classes, methods, variables,
labels, namespace, interfaces, etc. C# identifiers enforce the following rules: They can have
alphabets, digits and underscore character. They must not begin with a digit. Upper case and lower case
letters are distinct.
Literals are the way in which the values that are stored in variables are represented.
Operators are symbols used in expressions to describe operations involving one or more operands.
Punctuators are symbols used for grouping and separating code. Punctuators in C# include:
Parentheses, Braces, Brackets, Semicolon, Colon, Comma, Period.
C# implements several types of statements:
Empty Statements, Labeled Statement, Declaration statements, Expression statement, Selection
statement, Interaction statements, Jump statements, try statements, checked statements, unchecked
statements, lock statements, using statements.
Scope of Variables
The scope of variables is the region of code within which the variable can be accessed.
C# variables are categorized into
- Static variables
- Instance Variables
- Array elements
- Value Parameters
- Reference Parameters
- Output Parameters
- Local variables
the scope of variables are
- m is a static variable
- n is an instance variable
- a is a value parameter
- b is an reference parameter
- c is an output parameter
- arr is an array element
-d is a local variable.
Static and instance variables are declared at the class level and are known as fields and ends when the
main method terminates. The reference and output parameters do not create new storage locations,
they represent the same storage locations as the variables that are passed as arguments.
The scope of a local variables starts immediately after its identifier in the declaration and extends up to
the end of the block containing the declaration. C# makes a fundamental distinction between the field
variables declared at the class level and the local variables declared within methods.
Boxing and Unboxing
Boxing means the conversion of a value type on the stack to a object type on the heap, conversely, the
conversion from an object type back to a value type is known as unboxing.
Boxing – Any type, value or reference can be assigned to an object without an explicit conversion.
When the compiler finds a value type where it needs a reference type, it creates an object ‘Box’ into
which it places the value of the value type.
Unboxing – Unboxing is the process of converting the object type back to the value type. A variable
that has previously been boxed can only be unboxed. While unboxing the object could be cast to any
type.
class Sample
{
static int m; int n;
void Test (int a, ref int b, out int
c, int [] arr)
{ int d = 100; …………
}
}
Method Overloading
- C# allows us to create more than one method with the same name, but with the different parameter
lists and different definitions. This is called method overloading. - Method overloading is used
when methods are required to perform similar tasks but using different input parameters.
- Overloaded methods must differ in number and/or type of parameters they take. This enables the
compiler to decide which one of the definitions to execute depending on the type and number of
arguments in the method call. - using the concept of method overloading, a family of methods
with one name but different arguments lists can be designed.
The method selection involves the following steps: 1) The compiler tries to find an exact match in
which the types of actual parameters are same and uses that method. 2) if the exact match
is not found, then the compiler tries to use the implicit conversions to the actual arguments and then
uses the method whose match is unique. If the conversion creates multiple matches, then the compiler
will generate an error message.

Contenu connexe

Tendances

C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
Andrew Raj
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
birbal
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
Anil Dutt
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
Tony Apreku
 

Tendances (20)

Learn C# Programming - Operators
Learn C# Programming - OperatorsLearn C# Programming - Operators
Learn C# Programming - Operators
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
Ch6
Ch6Ch6
Ch6
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
Programming in C- Introduction
Programming in C- IntroductionProgramming in C- Introduction
Programming in C- Introduction
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
Assignment5
Assignment5Assignment5
Assignment5
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
C++
C++C++
C++
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++
 
Variables and data types in C++
Variables and data types in C++Variables and data types in C++
Variables and data types in C++
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Pc module1
Pc module1Pc module1
Pc module1
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
C material
C materialC material
C material
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 
C tokens
C tokensC tokens
C tokens
 

En vedette (9)

Is case study
Is   case studyIs   case study
Is case study
 
C# programs
C# programsC# programs
C# programs
 
C# chap 2
C# chap 2C# chap 2
C# chap 2
 
Wireless lan
Wireless lanWireless lan
Wireless lan
 
What is this
What is thisWhat is this
What is this
 
numbers system
numbers systemnumbers system
numbers system
 
Jstreams
JstreamsJstreams
Jstreams
 
Tech talk php_cms
Tech talk php_cmsTech talk php_cms
Tech talk php_cms
 
Tech talk webtech
Tech talk webtechTech talk webtech
Tech talk webtech
 

Similaire à C# chap 4

L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
MMRF2
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 

Similaire à C# chap 4 (20)

Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
Basic Structure Of C++
Basic Structure Of C++Basic Structure Of C++
Basic Structure Of C++
 
C language 3
C language 3C language 3
C language 3
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
c# at f#
c# at f#c# at f#
c# at f#
 
C# AND F#
C# AND F#C# AND F#
C# AND F#
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 

Plus de Shehrevar Davierwala

Plus de Shehrevar Davierwala (20)

Introduction_Swift
Introduction_SwiftIntroduction_Swift
Introduction_Swift
 
PsudoCode.pptx
PsudoCode.pptxPsudoCode.pptx
PsudoCode.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Java Script (Module 1).pptx
Java Script (Module 1).pptxJava Script (Module 1).pptx
Java Script (Module 1).pptx
 
Website in Clicks Day 2
Website in Clicks Day 2Website in Clicks Day 2
Website in Clicks Day 2
 
Develop Website in Clicks
Develop Website in ClicksDevelop Website in Clicks
Develop Website in Clicks
 
Build Virtual Assistant Using AI
Build Virtual Assistant Using AI Build Virtual Assistant Using AI
Build Virtual Assistant Using AI
 
Build brand reputation using facebook
Build brand reputation using facebookBuild brand reputation using facebook
Build brand reputation using facebook
 
Digital Marketing Session 2
Digital Marketing Session 2Digital Marketing Session 2
Digital Marketing Session 2
 
Learn Digital Marketing : 0 to Hero Day 1
Learn Digital Marketing :  0 to Hero Day 1 Learn Digital Marketing :  0 to Hero Day 1
Learn Digital Marketing : 0 to Hero Day 1
 
Standard template
Standard templateStandard template
Standard template
 
Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective  Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective
 
Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Developing stunning website in clicks - 2
Developing stunning website in clicks - 2
 
Developing stunning website in clicks
Developing stunning website in clicksDeveloping stunning website in clicks
Developing stunning website in clicks
 
Google forms for data analysis
Google forms for data analysisGoogle forms for data analysis
Google forms for data analysis
 
Webdesign session1
Webdesign session1Webdesign session1
Webdesign session1
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Java operators
Java operatorsJava operators
Java operators
 
Basic
BasicBasic
Basic
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

C# chap 4

  • 1. Chapter 4 Literals, variables and Data Types The smallest, non-reducible, textual elements in a program are referred to as Tokens. A C# program is a collection of tokens, comments and white spaces. C# include the following five types of tokens: Keywords, Identifiers, Literals, Operators, Punctuators Keywords are an essential part of a language definition. They implement specific features of the language. They are reserved, and cannot be used as identifiers except when they are prefaced by the @ character. Identifiers are programmer –designed tokens. They are used for naming classes, methods, variables, labels, namespace, interfaces, etc. C# identifiers enforce the following rules: They can have alphabets, digits and underscore character. They must not begin with a digit. Upper case and lower case letters are distinct. Literals are the way in which the values that are stored in variables are represented. Operators are symbols used in expressions to describe operations involving one or more operands. Punctuators are symbols used for grouping and separating code. Punctuators in C# include: Parentheses, Braces, Brackets, Semicolon, Colon, Comma, Period. C# implements several types of statements: Empty Statements, Labeled Statement, Declaration statements, Expression statement, Selection statement, Interaction statements, Jump statements, try statements, checked statements, unchecked statements, lock statements, using statements. Scope of Variables The scope of variables is the region of code within which the variable can be accessed. C# variables are categorized into - Static variables - Instance Variables - Array elements - Value Parameters - Reference Parameters - Output Parameters - Local variables
  • 2. the scope of variables are - m is a static variable - n is an instance variable - a is a value parameter - b is an reference parameter - c is an output parameter - arr is an array element -d is a local variable. Static and instance variables are declared at the class level and are known as fields and ends when the main method terminates. The reference and output parameters do not create new storage locations, they represent the same storage locations as the variables that are passed as arguments. The scope of a local variables starts immediately after its identifier in the declaration and extends up to the end of the block containing the declaration. C# makes a fundamental distinction between the field variables declared at the class level and the local variables declared within methods. Boxing and Unboxing Boxing means the conversion of a value type on the stack to a object type on the heap, conversely, the conversion from an object type back to a value type is known as unboxing. Boxing – Any type, value or reference can be assigned to an object without an explicit conversion. When the compiler finds a value type where it needs a reference type, it creates an object ‘Box’ into which it places the value of the value type. Unboxing – Unboxing is the process of converting the object type back to the value type. A variable that has previously been boxed can only be unboxed. While unboxing the object could be cast to any type. class Sample { static int m; int n; void Test (int a, ref int b, out int c, int [] arr) { int d = 100; ………… } }
  • 3. Method Overloading - C# allows us to create more than one method with the same name, but with the different parameter lists and different definitions. This is called method overloading. - Method overloading is used when methods are required to perform similar tasks but using different input parameters. - Overloaded methods must differ in number and/or type of parameters they take. This enables the compiler to decide which one of the definitions to execute depending on the type and number of arguments in the method call. - using the concept of method overloading, a family of methods with one name but different arguments lists can be designed. The method selection involves the following steps: 1) The compiler tries to find an exact match in which the types of actual parameters are same and uses that method. 2) if the exact match is not found, then the compiler tries to use the implicit conversions to the actual arguments and then uses the method whose match is unique. If the conversion creates multiple matches, then the compiler will generate an error message.