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
Vishwa Mohan
 
PPT
Introduction to c#
OpenSource Technologies Pvt. Ltd.
 
ODP
OOP java
xball977
 
PPT
C# basics
Dinesh kumar
 
PPT
Introduction To C#
SAMIR BHOGAYTA
 
PPT
Looping statements in Java
Jin Castor
 
PPT
C sharp
Satish Verma
 
PPT
Oop java
Minal Maniar
 
CSharp Presentation
Vishwa Mohan
 
OOP java
xball977
 
C# basics
Dinesh kumar
 
Introduction To C#
SAMIR BHOGAYTA
 
Looping statements in Java
Jin Castor
 
C sharp
Satish Verma
 
Oop java
Minal Maniar
 

What's hot (20)

PPT
C# Basics
Sunil OS
 
PPTX
C# Delegates
Raghuveer Guthikonda
 
PPTX
C# classes objects
Dr.Neeraj Kumar Pandey
 
PPTX
C# 101: Intro to Programming with C#
Hawkman Academy
 
PPT
C# Exceptions Handling
sharqiyem
 
PDF
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
PPTX
Array in c#
Prem Kumar Badri
 
PPTX
C sharp
sanjay joshi
 
PPTX
Operators and expression in c#
Dr.Neeraj Kumar Pandey
 
PPTX
Abstract Class Presentation
tigerwarn
 
PPTX
Type casting
Ruchika Sinha
 
PPTX
C# programming language
swarnapatil
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPT
PL/SQL Introduction and Concepts
Bharat Kalia
 
PPTX
Array in Java
Ali shah
 
PPTX
Object Oriented Programing JAVA presentaion
Pritom Chaki
 
PPTX
C# in depth
Arnon Axelrod
 
PPT
7.data types in c#
Zeeshan Ahmad
 
PPTX
C# File IO Operations
Prem Kumar Badri
 
PPT
Applets
SanthiNivas
 
C# Basics
Sunil OS
 
C# Delegates
Raghuveer Guthikonda
 
C# classes objects
Dr.Neeraj Kumar Pandey
 
C# 101: Intro to Programming with C#
Hawkman Academy
 
C# Exceptions Handling
sharqiyem
 
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
Array in c#
Prem Kumar Badri
 
C sharp
sanjay joshi
 
Operators and expression in c#
Dr.Neeraj Kumar Pandey
 
Abstract Class Presentation
tigerwarn
 
Type casting
Ruchika Sinha
 
C# programming language
swarnapatil
 
Java exception handling
BHUVIJAYAVELU
 
PL/SQL Introduction and Concepts
Bharat Kalia
 
Array in Java
Ali shah
 
Object Oriented Programing JAVA presentaion
Pritom Chaki
 
C# in depth
Arnon Axelrod
 
7.data types in c#
Zeeshan Ahmad
 
C# File IO Operations
Prem Kumar Badri
 
Applets
SanthiNivas
 
Ad

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

PDF
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
MMRF2
 
PPT
Literals,variables,datatype in C#
Prasanna Kumar SM
 
PPTX
CS4443 - Modern Programming Language - I Lecture (2)
Dilawar Khan
 
PPT
Visula C# Programming Lecture 2
Abou Bakr Ashraf
 
PPTX
Chapter3: fundamental programming
Ngeam Soly
 
PPTX
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
DOCX
Unit 1 question and answer
Vasuki Ramasamy
 
PDF
C sharp chap2
Mukesh Tekwani
 
PPTX
2 programming with c# i
siragezeynu
 
PPTX
Chapter 2 c#
megersaoljira
 
PPTX
Core C# Programming Constructs, Part 1
Vahid Farahmandian
 
PDF
Lesson 1 INTRODUCTION TO C# LANGUAGE.pdf
John Burca
 
PPTX
CSharp Language Overview Part 1
Hossein Zahed
 
PPTX
C# Basics
vijayakumari kaliannan
 
PPTX
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
PDF
CSharpCheatSheetV1.pdf
ssusera0bb35
 
PPTX
C# basics
sagaroceanic11
 
PDF
2.Getting Started with C#.Net-(C#)
Shoaib Ghachi
 
PDF
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
MMRF2
 
Literals,variables,datatype in C#
Prasanna Kumar SM
 
CS4443 - Modern Programming Language - I Lecture (2)
Dilawar Khan
 
Visula C# Programming Lecture 2
Abou Bakr Ashraf
 
Chapter3: fundamental programming
Ngeam Soly
 
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
Unit 1 question and answer
Vasuki Ramasamy
 
C sharp chap2
Mukesh Tekwani
 
2 programming with c# i
siragezeynu
 
Chapter 2 c#
megersaoljira
 
Core C# Programming Constructs, Part 1
Vahid Farahmandian
 
Lesson 1 INTRODUCTION TO C# LANGUAGE.pdf
John Burca
 
CSharp Language Overview Part 1
Hossein Zahed
 
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
CSharpCheatSheetV1.pdf
ssusera0bb35
 
C# basics
sagaroceanic11
 
2.Getting Started with C#.Net-(C#)
Shoaib Ghachi
 
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
Ad

More from Dr.Neeraj Kumar Pandey (18)

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

Recently uploaded (20)

PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Software Development Methodologies in 2025
KodekX
 
Software Development Company | KodekX
KodekX
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 

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