SlideShare a Scribd company logo
5
Most read
6
Most read
8
Most read
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

PPTX
CSharp Presentation
PPT
Introduction To C#
PPT
PPTX
C# classes objects
PDF
Learn C# Programming - Decision Making & Loops
PPSX
Data Types & Variables in JAVA
PPTX
Functions in c++
PDF
Learn C# Programming - Data Types & Type Conversion
CSharp Presentation
Introduction To C#
C# classes objects
Learn C# Programming - Decision Making & Loops
Data Types & Variables in JAVA
Functions in c++
Learn C# Programming - Data Types & Type Conversion

What's hot (20)

PPTX
Data Types, Variables, and Operators
PPTX
C# 101: Intro to Programming with C#
PPTX
PPT
C# basics
PPTX
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
PPTX
Pure virtual function and abstract class
PPT
C# Basics
PPTX
Data types in c++
PPT
7.data types in c#
PPTX
Delegates and events in C#
PPSX
C# - Part 1
PDF
Function overloading ppt
PPT
C#.NET
PPT
PHP - Introduction to Object Oriented Programming with PHP
PPTX
I/O Streams
PDF
itft-Decision making and branching in java
PPTX
Inline function
PPTX
Introduction to C# Programming
PPT
Methods in C#
PDF
Constructors and destructors
Data Types, Variables, and Operators
C# 101: Intro to Programming with C#
C# basics
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
Pure virtual function and abstract class
C# Basics
Data types in c++
7.data types in c#
Delegates and events in C#
C# - Part 1
Function overloading ppt
C#.NET
PHP - Introduction to Object Oriented Programming with PHP
I/O Streams
itft-Decision making and branching in java
Inline function
Introduction to C# Programming
Methods in C#
Constructors and destructors
Ad

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

DOCX
Unit 1 question and answer
PPTX
C programming tutorial for Beginner
DOCX
Uniti classnotes
PDF
Interview Questions For C Language
PPTX
Interview Questions For C Language .pptx
PDF
C programming notes.pdf
PDF
C programming notes
PPT
C the basic concepts
PPTX
Data Type in C Programming
PPTX
fundamentals of c
PPTX
Msc prev updated
PPTX
Msc prev completed
PPTX
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ODP
CProgrammingTutorial
PDF
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
PDF
Cp presentation
PPTX
C Program basic concepts using c knoweledge
DOCX
C programming tutorial
PDF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PPT
SPC Unit 2
Unit 1 question and answer
C programming tutorial for Beginner
Uniti classnotes
Interview Questions For C Language
Interview Questions For C Language .pptx
C programming notes.pdf
C programming notes
C the basic concepts
Data Type in C Programming
fundamentals of c
Msc prev updated
Msc prev completed
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
CProgrammingTutorial
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
Cp presentation
C Program basic concepts using c knoweledge
C programming tutorial
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
SPC Unit 2
Ad

More from Dr.Neeraj Kumar Pandey (18)

PPTX
Structure in c#
PPTX
Strings in c#
PPTX
Program control statements in c#
PPTX
Operators and expression in c#
PPTX
Method parameters in c#
PPTX
Enumeration in c#
PPTX
Dot net assembly
PPT
Cloud introduction
PPTX
Role of cloud computing in scm
PPTX
PPTX
cloud computing Multi cloud
PPTX
Ibm bluemix case study
PPTX
Business cases for the need of cloud computing
PPT
cloud computing:Types of virtualization
PPTX
cloud computing: Vm migration
PPTX
Cloud Computing: Virtualization
PPT
Dot net introduction
PPTX
C# lecture 1: Introduction to Dot Net Framework
Structure in c#
Strings in c#
Program control statements in c#
Operators and expression in c#
Method parameters in c#
Enumeration in c#
Dot net assembly
Cloud introduction
Role of cloud computing in scm
cloud computing Multi cloud
Ibm bluemix case study
Business cases for the need of cloud computing
cloud computing:Types of virtualization
cloud computing: Vm migration
Cloud Computing: Virtualization
Dot net introduction
C# lecture 1: Introduction to Dot Net Framework

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Group 1 Presentation -Planning and Decision Making .pptx
Machine Learning_overview_presentation.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Dropbox Q2 2025 Financial Results & Investor Presentation

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