SlideShare a Scribd company logo
C# Tutorial
Part 5: Variable, Datatype,
Keywords
www.sirykt.blogspot.com
• A variable is nothing but a name given to a
storage area that our programs can
manipulate.
• Each variable in C# has a specific type, which
determines the size and layout of the variable's
memory the range of values that can be stored
within that memory and the set of operations
that can be applied to the variable.
• Static variable:
• Static variables memory allocates in the class memory
• The static variable value we can maintain continuously until closing
the application
• We can't destroy static variable value
• The static variable features we can share with all class objects
• We can saves the application memory purpose using static variable
• Normal variable:
• Normal variables memory allocates in the objects memory
• This value we can't maintain continuously until closing the app
• We can destroy the normal variable value
• The normal variable features we can't share with class objects
• We can't saves the application memory.
example on static & normal variable
• using System;
• using System.Collections.Generic;
• using System.Linq;
• using System.Text;
• using System.Threading.Tasks;
• namespace ConsoleApplication20
• { class m1//class name
• { static int a, b, c;//static variables
• public void add()//non static method
• { a = 100;
• b = 200;
• c = a + b;
• Console.WriteLine(c.ToString());
• Console.ReadLine(); }
• public static void display()//static method
• { a = 500;
• b = 500;
• c = a + b;
• Console.WriteLine(c.ToString());
• Console.ReadLine(); }
• static void Main(string[] args)
• { m1 obj = new m1();//non static methods create the instance
• obj.add();//object through calling the method
• m1.display();//static variable directly access by the class
name
• } } }
• note:
• A static class is basically the same as a non-static class, but there is
one difference: a static class cannot be instantiated.
• In other words, we cannot use the new keyword to create a variable of
the class type.
• Because there is no instance variable, we access the members of a static
class by using the class name itself
• A data type specifies the type of data that a variable can store such as integer,
floating, character etc.
The basic value types provided in C# can be categorized as:
Type Example
Integral types sbyte, byte, short, ushort, int, uint, long, ulong, and
char
Floating point
types
float and double
Decimal types decimal
Boolean types true or false values, as assigned
Nullable types Nullable data types
Types Data Types
Value Data Type int, char, float, Boolean, etc
Reference Data Type String, Class, Object and Interface
Pointer Data Type Pointers
Value Data Type
• The value data types are integer-based and floating-point based. C#
language supports both signed and unsigned literals.
• There are 2 types of value data type in C# language.
• 1) Predefined Data Types - such as Integer, Boolean, Float,
etc.
• 2) User defined Data Types - such as Structure,
Enumerations, etc.
Data Types Memory Size Range
char 1 byte -128 to 127
signed char 1 byte -128 to 127
unsigned char 1 byte 0 to 127
short 2 byte -32,768 to 32,767
signed short 2 byte -32,768 to 32,767
unsigned short 2 byte 0 to 32,767
int 2 byte -32,768 to 32,767
signed int 2 byte -32,768 to 32,767
unsigned int 2 byte 0 to 32,767
short int 2 byte -32,768 to 32,767
signed short int 2 byte -32,768 to 32,767
unsigned short int 2 byte 0 to 32,767
long int 4 byte
signed long int 4 byte
unsigned long int 4 byte
float 4 byte
double 8 byte
long double 10 byte
Reference Data Type
• The reference data types do not contain the actual data stored in a
variable, but they contain a reference to the variables.
• If the data is changed by one of the variables, the other variable
automatically reflects this change in value.
• There are 2 types of reference data type in C# language.
• 1) Predefined Types - such as Objects, String.
• 2) User defined Types - such as Classes, Interface.
Pointer Data Type
• The pointer in C# language is a variable, it is also known as locator or indicator
that points to an address of a value.
Symbol Name Description
& (ampersand sign) Address operator Determine the address of a variable.
* (asterisk sign) Indirection operator Access the value of an address.
Print the limits of datatypes
• using System;
• namespace printthelimitsofdatatypes
• { class Program
• { static void Main(string[] args)
• { Console.WriteLine(byte.MinValue.ToString());
• Console.WriteLine(byte.MaxValue.ToString());
• Console.WriteLine(int.MinValue.ToString());
• Console.WriteLine(int.MaxValue.ToString());
• Console.WriteLine(short.MinValue.ToString());
• Console.WriteLine(short.MaxValue.ToString());
• Console.WriteLine(long.MinValue.ToString());
• Console.WriteLine(long.MaxValue.ToString());
• Console.WriteLine(float.MinValue.ToString());
• Console.WriteLine(float.MaxValue.ToString());
• Console.WriteLine(double.MinValue.ToString());
• Console.WriteLine(double.MaxValue.ToString());
• Console.WriteLine(decimal.MinValue.ToString());
• Console.WriteLine(decimal.MaxValue.ToString());
• Console.ReadLine();
• }}}
o/p:
• 0
• 255
• -2147483648
• 2147483647
• -32768
• 32767
• -9223372036854775808
• 9223372036854775807
• -3.402823E+38
• 3.402823E+38
• -1.79769313486232E+308
• 1.79769313486232E+308
• -79228162514264337593543950335
• 79228162514264337593543950335
Keywords
• A keyword is a reserved word. You cannot use it as a variable name, constant
name etc.
• In C# keywords cannot be used as identifiers.
• However, if we want to use the keywords as identifiers, we may prefix the
keyword with @ character.
abstract base as bool break catch case
byte char checked class const continue decimal
private protected public return readonly ref sbyte
explicit extern false finally fixed float for
foreach goto if implicit in in (generic
modifier)
int
ulong ushort unchecked using unsafe virtual void
null object operator out out (generic
modifier)
override params
default delegate do double else enum event
sealed short sizeof stackalloc static string struct
switch this throw true try typeof uint
abstract base as bool break catch case
volatile while
SIRYKT
Sharing Knowledge is Learning
For more updates
For more visit our website www.sirykt.blogspot.com

More Related Content

What's hot

Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
sasi saseenthiran
 
Java Datatypes
Java DatatypesJava Datatypes
Java Datatypes
Mayank Aggarwal
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
Soba Arjun
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Net framework
Net frameworkNet framework
Net framework
Abhishek Mukherjee
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
Berk Soysal
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
Berk Soysal
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types
3trg
 
Basic Operator, String and Characters in Swift.
Basic Operator, String and Characters in Swift.Basic Operator, String and Characters in Swift.
Basic Operator, String and Characters in Swift.
HSIEH CHING-FAN
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
Berk Soysal
 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithms
Nico Ludwig
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
Ahmad Idrees
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
Ahmad Idrees
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVAHamna_sheikh
 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithms
Nico Ludwig
 
Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3
Berk Soysal
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
SAMIR BHOGAYTA
 

What's hot (20)

C# basics
 C# basics C# basics
C# basics
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Java Datatypes
Java DatatypesJava Datatypes
Java Datatypes
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Net framework
Net frameworkNet framework
Net framework
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types
 
Basic Operator, String and Characters in Swift.
Basic Operator, String and Characters in Swift.Basic Operator, String and Characters in Swift.
Basic Operator, String and Characters in Swift.
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithms
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVA
 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithms
 
Data type
Data typeData type
Data type
 
Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 

Similar to 5variables in c#

C language
C languageC language
C language
Mukul Kirti Verma
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
Dilawar Khan
 
Aspdot
AspdotAspdot
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
Ainuddin Yousufzai
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data types
SasidharaRaoMarrapu
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
LECO9
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
SKUP1
 
What is Data Types and Functions?
What is Data Types and Functions?What is Data Types and Functions?
What is Data Types and Functions?
AnuragSrivastava272
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
C PROGRAMING.pptx
C PROGRAMING.pptxC PROGRAMING.pptx
C PROGRAMING.pptx
MohammedtajuddinTaju
 
C
CC
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
sophoeutsen2
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
Christian Nagel
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET Core
Christian Nagel
 
Java ce241
Java ce241Java ce241
Java ce241
Minal Maniar
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
praveenaprakasam
 

Similar to 5variables in c# (20)

C language
C languageC language
C language
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
 
Aspdot
AspdotAspdot
Aspdot
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data types
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
 
What is Data Types and Functions?
What is Data Types and Functions?What is Data Types and Functions?
What is Data Types and Functions?
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
C PROGRAMING.pptx
C PROGRAMING.pptxC PROGRAMING.pptx
C PROGRAMING.pptx
 
C
CC
C
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET Core
 
Java ce241
Java ce241Java ce241
Java ce241
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 

More from Sireesh K

Cn10
Cn10Cn10
Cn10
Sireesh K
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
Sireesh K
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
Sireesh K
 
What is mvc
What is mvcWhat is mvc
What is mvc
Sireesh K
 
31c
31c31c
31cs
31cs31cs
31cs
Sireesh K
 
45c
45c45c
44c
44c44c
43c
43c43c
42c
42c42c
41c
41c41c
40c
40c40c
39c
39c39c
38c
38c38c
37c
37c37c
35c
35c35c
34c
34c34c
33c
33c33c
30c
30c30c
29c
29c29c

More from Sireesh K (20)

Cn10
Cn10Cn10
Cn10
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
What is mvc
What is mvcWhat is mvc
What is mvc
 
31c
31c31c
31c
 
31cs
31cs31cs
31cs
 
45c
45c45c
45c
 
44c
44c44c
44c
 
43c
43c43c
43c
 
42c
42c42c
42c
 
41c
41c41c
41c
 
40c
40c40c
40c
 
39c
39c39c
39c
 
38c
38c38c
38c
 
37c
37c37c
37c
 
35c
35c35c
35c
 
34c
34c34c
34c
 
33c
33c33c
33c
 
30c
30c30c
30c
 
29c
29c29c
29c
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

5variables in c#

  • 1. C# Tutorial Part 5: Variable, Datatype, Keywords www.sirykt.blogspot.com
  • 2. • A variable is nothing but a name given to a storage area that our programs can manipulate. • Each variable in C# has a specific type, which determines the size and layout of the variable's memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable.
  • 3. • Static variable: • Static variables memory allocates in the class memory • The static variable value we can maintain continuously until closing the application • We can't destroy static variable value • The static variable features we can share with all class objects • We can saves the application memory purpose using static variable
  • 4. • Normal variable: • Normal variables memory allocates in the objects memory • This value we can't maintain continuously until closing the app • We can destroy the normal variable value • The normal variable features we can't share with class objects • We can't saves the application memory.
  • 5. example on static & normal variable • using System; • using System.Collections.Generic; • using System.Linq; • using System.Text; • using System.Threading.Tasks; • namespace ConsoleApplication20 • { class m1//class name • { static int a, b, c;//static variables • public void add()//non static method • { a = 100; • b = 200; • c = a + b; • Console.WriteLine(c.ToString()); • Console.ReadLine(); } • public static void display()//static method • { a = 500; • b = 500; • c = a + b; • Console.WriteLine(c.ToString()); • Console.ReadLine(); } • static void Main(string[] args)
  • 6. • { m1 obj = new m1();//non static methods create the instance • obj.add();//object through calling the method • m1.display();//static variable directly access by the class name • } } } • note: • A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. • In other words, we cannot use the new keyword to create a variable of the class type. • Because there is no instance variable, we access the members of a static class by using the class name itself
  • 7. • A data type specifies the type of data that a variable can store such as integer, floating, character etc.
  • 8. The basic value types provided in C# can be categorized as: Type Example Integral types sbyte, byte, short, ushort, int, uint, long, ulong, and char Floating point types float and double Decimal types decimal Boolean types true or false values, as assigned Nullable types Nullable data types
  • 9. Types Data Types Value Data Type int, char, float, Boolean, etc Reference Data Type String, Class, Object and Interface Pointer Data Type Pointers
  • 10. Value Data Type • The value data types are integer-based and floating-point based. C# language supports both signed and unsigned literals. • There are 2 types of value data type in C# language. • 1) Predefined Data Types - such as Integer, Boolean, Float, etc. • 2) User defined Data Types - such as Structure, Enumerations, etc.
  • 11. Data Types Memory Size Range char 1 byte -128 to 127 signed char 1 byte -128 to 127 unsigned char 1 byte 0 to 127 short 2 byte -32,768 to 32,767 signed short 2 byte -32,768 to 32,767 unsigned short 2 byte 0 to 32,767 int 2 byte -32,768 to 32,767 signed int 2 byte -32,768 to 32,767 unsigned int 2 byte 0 to 32,767 short int 2 byte -32,768 to 32,767 signed short int 2 byte -32,768 to 32,767 unsigned short int 2 byte 0 to 32,767 long int 4 byte signed long int 4 byte unsigned long int 4 byte float 4 byte double 8 byte long double 10 byte
  • 12. Reference Data Type • The reference data types do not contain the actual data stored in a variable, but they contain a reference to the variables. • If the data is changed by one of the variables, the other variable automatically reflects this change in value. • There are 2 types of reference data type in C# language. • 1) Predefined Types - such as Objects, String. • 2) User defined Types - such as Classes, Interface.
  • 13. Pointer Data Type • The pointer in C# language is a variable, it is also known as locator or indicator that points to an address of a value. Symbol Name Description & (ampersand sign) Address operator Determine the address of a variable. * (asterisk sign) Indirection operator Access the value of an address.
  • 14. Print the limits of datatypes • using System; • namespace printthelimitsofdatatypes • { class Program • { static void Main(string[] args) • { Console.WriteLine(byte.MinValue.ToString()); • Console.WriteLine(byte.MaxValue.ToString()); • Console.WriteLine(int.MinValue.ToString()); • Console.WriteLine(int.MaxValue.ToString()); • Console.WriteLine(short.MinValue.ToString()); • Console.WriteLine(short.MaxValue.ToString()); • Console.WriteLine(long.MinValue.ToString()); • Console.WriteLine(long.MaxValue.ToString()); • Console.WriteLine(float.MinValue.ToString()); • Console.WriteLine(float.MaxValue.ToString()); • Console.WriteLine(double.MinValue.ToString()); • Console.WriteLine(double.MaxValue.ToString()); • Console.WriteLine(decimal.MinValue.ToString()); • Console.WriteLine(decimal.MaxValue.ToString()); • Console.ReadLine(); • }}}
  • 15. o/p: • 0 • 255 • -2147483648 • 2147483647 • -32768 • 32767 • -9223372036854775808 • 9223372036854775807 • -3.402823E+38 • 3.402823E+38 • -1.79769313486232E+308 • 1.79769313486232E+308 • -79228162514264337593543950335 • 79228162514264337593543950335
  • 16. Keywords • A keyword is a reserved word. You cannot use it as a variable name, constant name etc. • In C# keywords cannot be used as identifiers. • However, if we want to use the keywords as identifiers, we may prefix the keyword with @ character.
  • 17. abstract base as bool break catch case byte char checked class const continue decimal private protected public return readonly ref sbyte explicit extern false finally fixed float for foreach goto if implicit in in (generic modifier) int ulong ushort unchecked using unsafe virtual void null object operator out out (generic modifier) override params default delegate do double else enum event sealed short sizeof stackalloc static string struct switch this throw true try typeof uint abstract base as bool break catch case volatile while
  • 19. For more updates For more visit our website www.sirykt.blogspot.com