SlideShare uma empresa Scribd logo
1 de 19
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

Mais conteúdo relacionado

Mais procurados

Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variablessasi saseenthiran
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypesSoba Arjun
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1Berk Soysal
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4Berk Soysal
 
Java basic data types
Java basic data typesJava basic data types
Java basic data types3trg
 
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 6Berk Soysal
 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithmsNico 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 algorithmsNico Ludwig
 
Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3Berk 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
 

Mais procurados (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#
 

Semelhante a 5variables in c#

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
 
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 typesSasidharaRaoMarrapu
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxLECO9
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxSKUP1
 
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 NeedsRaja Sekhar
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginnersophoeutsen2
 
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 2019Christian Nagel
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve 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 CoreChristian Nagel
 

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

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

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 

Último (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 

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