SlideShare a Scribd company logo
1 of 11
Dr. Neeraj Kumar Pandey
Literals , Variables and
Data Types in C#
INDEX
• Introduction.
• Keywords in C#.
• Identifiers in C#.
• Literals in C#.
• Punctuators in C#.
• Data types in C#.
Introduction
• Programming language is designed to manipulate certain kinds
of data consisting of numbers, characters and strings and
provide useful output known as information to the user.
• A task of manipulating data is performed by executing a
sequence of instructions constituting what is known as a
program.
• These instructions are formed using certain symbols and words
according to some rigid rules known as syntax rules.
• C# program is a collection of tokens, comments and white
spaces . C# includes the following five types of tokens:
1. Keywords 2. Identifiers 3.Literals 4.Operators 5.Punctuators.
Keywords in C#
1) Keywords are the essential parts of a language definition.
2) They implement specific features of the language.
3) They are reserved and can not be used as identifiers except when they are prefaced
by the @ character.
Identifiers in C#
 In C#, an identifier is a name assigned to a method, a variable, or any other user-defined
item.
 Identifiers can be one or more characters long. Variable names may start with any
letter of the alphabet or an underscore.
 Identifiers containing two consecutive underscores, such as max_ _value, are reserved for
use by the compiler.
 Uppercase and lowercase are different; that is, to C#, myvar and MyVar are separate
names.
// Demonstrate an @ identifier.
using System;
class IdTest {
static void Main() {
int @if; // use if as an identifier
for(@if = 0; @if < 10; @if++)
Console.WriteLine("@if is " + @if);
}
}
Literals in C#
These are value constants assigned to variables (or result of expression) in a program.
Ex. 121,-67,0,65432 Ex. 0.0087, -0.75, 453.67
Ex. True,false
Ex. ‘5’ , ‘c’, ‘;’ “Hello C#” , “2001”, “?....”
Backslash character literal: ‘a’ alert , ‘b’ back space, ‘n’ new line , ‘t’ horizontal tab
‘v’ vertical tab etc
Punctuator in C#
Punctuators (known as separators)are symbols used in expressions to
describe operations involving one or more operands of a program.
1. Parentheses ( )
2. Braces { }
3. Brackets [ ]
4. Semicolon ;
5. Colon :
6. Comma ,
7. Period .
Data Types used in C#
Variable: a variable is an identifier that denotes a storage location used to store a data value
And a variable can change during execution of a program.
Every variable in C# is associated with a data type . Data type specify the size and type of
values that can be stored.
- Values types stored in stack. and when value
of one variable assigned to other variable
then the value is actual copied and two copies
of the values are available In memory.
- Reference types stored in heap. When
assignment is done then reference is copied
so actual value will be remain same but
two references point to a single value.
Values Type
Values type of c# is divided in two categories
1. User defined type (complex type).
2. Predefined type (primitive or simple type).
Integral Type
Signed Integer
Unsigned Integer
Wider data types require more time
For execution so try to use data type
According to the requirement.
Floating point type
1. Float type values are single precision numbers with a precision
of 7 bit.
2. Double types represent double precision numbers with 15/16 bits.
Size and range of floating point numbers
Decimal Type: Decimal type is high precision . 128 bit data types that is designed for use in
financial and monetary calculation it can store 1x10-28 to 1x1028
Character Type: character type data represented by char and sizes is of two byte to hold single
Character.
Boolean Type: It is used when we want to test a particular condition during the execution of
the program there are only two values that a Boolean type can take : true or false. Boolean type
Can be declare by using keyword bool and uses only one bit of storage.
We can not use zero for false and non zero for true like in C/C++.

More Related Content

What's hot

11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
kapil078
 

What's hot (20)

11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
 
Servlets
ServletsServlets
Servlets
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
C# programming language
C# programming languageC# programming language
C# programming language
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Java IO
Java IOJava IO
Java IO
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
C#.NET
C#.NETC#.NET
C#.NET
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
C# String
C# StringC# String
C# String
 

Similar to C# lecture 2: Literals , Variables and Data Types in C#

C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 

Similar to C# lecture 2: Literals , Variables and Data Types in C# (20)

Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
Uniti classnotes
Uniti classnotesUniti classnotes
Uniti classnotes
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptx
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
C programming notes
C programming notesC programming notes
C programming notes
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
fundamentals of c
fundamentals of cfundamentals of c
fundamentals of c
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
 
Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
 
Cp presentation
Cp presentationCp presentation
Cp presentation
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
SPC Unit 2
SPC Unit 2SPC Unit 2
SPC Unit 2
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
C#
C#C#
C#
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 

More from Dr.Neeraj Kumar Pandey

More from Dr.Neeraj Kumar Pandey (19)

Structure in c#
Structure in c#Structure in c#
Structure in c#
 
Strings in c#
Strings in c#Strings in c#
Strings in c#
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Operators and expression in c#
Operators and expression in c#Operators and expression in c#
Operators and expression in c#
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Dot net assembly
Dot net assemblyDot net assembly
Dot net assembly
 
Cloud introduction
Cloud introductionCloud introduction
Cloud introduction
 
Role of cloud computing in scm
Role of cloud computing in scmRole of cloud computing in scm
Role of cloud computing in scm
 
Public cloud
Public cloudPublic cloud
Public cloud
 
cloud computing Multi cloud
cloud computing Multi cloudcloud computing Multi cloud
cloud computing Multi cloud
 
Ibm bluemix case study
Ibm bluemix case studyIbm bluemix case study
Ibm bluemix case study
 
Business cases for the need of cloud computing
Business cases for the need of cloud computingBusiness cases for the need of cloud computing
Business cases for the need of cloud computing
 
cloud computing:Types of virtualization
cloud computing:Types of virtualizationcloud computing:Types of virtualization
cloud computing:Types of virtualization
 
cloud computing: Vm migration
cloud computing: Vm migrationcloud computing: Vm migration
cloud computing: Vm migration
 
Cloud Computing: Virtualization
Cloud Computing: VirtualizationCloud Computing: Virtualization
Cloud Computing: Virtualization
 
Dot net introduction
Dot net introductionDot net introduction
Dot net introduction
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net Framework
 

Recently uploaded

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
 
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
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
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
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

C# lecture 2: Literals , Variables and Data Types in C#

  • 1. Dr. Neeraj Kumar Pandey Literals , Variables and Data Types in C#
  • 2. INDEX • Introduction. • Keywords in C#. • Identifiers in C#. • Literals in C#. • Punctuators in C#. • Data types in C#.
  • 3. Introduction • Programming language is designed to manipulate certain kinds of data consisting of numbers, characters and strings and provide useful output known as information to the user. • A task of manipulating data is performed by executing a sequence of instructions constituting what is known as a program. • These instructions are formed using certain symbols and words according to some rigid rules known as syntax rules. • C# program is a collection of tokens, comments and white spaces . C# includes the following five types of tokens: 1. Keywords 2. Identifiers 3.Literals 4.Operators 5.Punctuators.
  • 4. Keywords in C# 1) Keywords are the essential parts of a language definition. 2) They implement specific features of the language. 3) They are reserved and can not be used as identifiers except when they are prefaced by the @ character.
  • 5. Identifiers in C#  In C#, an identifier is a name assigned to a method, a variable, or any other user-defined item.  Identifiers can be one or more characters long. Variable names may start with any letter of the alphabet or an underscore.  Identifiers containing two consecutive underscores, such as max_ _value, are reserved for use by the compiler.  Uppercase and lowercase are different; that is, to C#, myvar and MyVar are separate names. // Demonstrate an @ identifier. using System; class IdTest { static void Main() { int @if; // use if as an identifier for(@if = 0; @if < 10; @if++) Console.WriteLine("@if is " + @if); } }
  • 6. Literals in C# These are value constants assigned to variables (or result of expression) in a program. Ex. 121,-67,0,65432 Ex. 0.0087, -0.75, 453.67 Ex. True,false Ex. ‘5’ , ‘c’, ‘;’ “Hello C#” , “2001”, “?....” Backslash character literal: ‘a’ alert , ‘b’ back space, ‘n’ new line , ‘t’ horizontal tab ‘v’ vertical tab etc
  • 7. Punctuator in C# Punctuators (known as separators)are symbols used in expressions to describe operations involving one or more operands of a program. 1. Parentheses ( ) 2. Braces { } 3. Brackets [ ] 4. Semicolon ; 5. Colon : 6. Comma , 7. Period .
  • 8. Data Types used in C# Variable: a variable is an identifier that denotes a storage location used to store a data value And a variable can change during execution of a program. Every variable in C# is associated with a data type . Data type specify the size and type of values that can be stored. - Values types stored in stack. and when value of one variable assigned to other variable then the value is actual copied and two copies of the values are available In memory. - Reference types stored in heap. When assignment is done then reference is copied so actual value will be remain same but two references point to a single value.
  • 9. Values Type Values type of c# is divided in two categories 1. User defined type (complex type). 2. Predefined type (primitive or simple type).
  • 10. Integral Type Signed Integer Unsigned Integer Wider data types require more time For execution so try to use data type According to the requirement.
  • 11. Floating point type 1. Float type values are single precision numbers with a precision of 7 bit. 2. Double types represent double precision numbers with 15/16 bits. Size and range of floating point numbers Decimal Type: Decimal type is high precision . 128 bit data types that is designed for use in financial and monetary calculation it can store 1x10-28 to 1x1028 Character Type: character type data represented by char and sizes is of two byte to hold single Character. Boolean Type: It is used when we want to test a particular condition during the execution of the program there are only two values that a Boolean type can take : true or false. Boolean type Can be declare by using keyword bool and uses only one bit of storage. We can not use zero for false and non zero for true like in C/C++.