SlideShare a Scribd company logo
1 of 13
C# Tutorial
Part 19:Typecasting
www.siri-kt.blogspot.com
• we can convert one datatype into different datatypes.
• it is classified into 2 types
• 1.implicit type casting
• 2.explicit type casting
• 1.implicit type casting:
• In this we convert lower datatypes are converts into higher data types.it is also called
as internal type casting. It is under control of clr;
• using System;
• namespace implicittypecastin_exm
• { class Program
• { static void Main(string[] args)
• { int i = 545454;//4 bytes
• long l = i;//8 bytes
• Console.WriteLine("the long value is:" + l.ToString());
• Console.ReadLine();
• } } }
• 2.Explicit type casting:
• In this we convert higher datatypes converts into lower datatypes. it is also called as
external type casting. this is under control of the programmer
• using System;
• namespace implicittypecastin_exm
• { class Program
• { static void Main(string[] args)
• { long l = 454545454;//8 bytes
• int i = l;//4 bytes
• Console.WriteLine("the int value is:" + i.ToString());
• Console.ReadLine();
• } } }
• the above example gives error. cant implicit convert higher to lower datatypes. we can
overcome this problem.explit type casting classified into
• 3 types :
• 1.c++ style type casting
• 2.parsing
• 3.converting
• 1.c++ style type casting:
• in this type casting higher datatypes are converts into lower datatypes.
• ex:
• long l = 454545454;//8 bytes
• int i =(int) l;//4 bytes
• Console.WriteLine("the int value is:" + i.ToString());
• Console.ReadLine();
• 2.working with parsing:
• as .net all the datatypes are predefined structures.
• int i;
• int-structure
• i-structure variable.
C# Type Conversion Methods
C# provides the following built-in type conversion methods:
Methods & Description
ToBoolean Converts a type to a Boolean value, where possible.
ToByte Converts a type to a byte.
ToChar Converts a type to a single Unicode character, where possible.
ToDateTime Converts a type (integer or string type) to date-time structures.
ToDecimal Converts a floating point or integer type to a decimal type.
ToDouble Converts a type to a double type.
ToInt16 Converts a type to a 16-bit integer.
ToInt32 Converts a type to a 32-bit integer.
ToInt64 Converts a type to a 64-bit integer.
ToSbyte Converts a type to a signed byte type.
ToSingle Converts a type to a small floating point number.
ToString Converts a type to a string.
ToType Converts a type to a specified type.
ToUInt16 Converts a type to an unsigned int type.
ToUInt32 Converts a type to an unsigned long type.
ToUInt64 Converts a type to an unsigned big integer.
• structure is a collection of predefined methods
• 1.minvalue()
• 2.maxvalue()
• 3.tostring()
• 4.parse()
• working with parse() is called as parsing. parse() method can be used only to convert
from strings into int. tostring() can be used only to convert from int to string.
• ex: print the limits of datatypes.
• 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.ReadLine(); }
• 2.example on parsing
• 1.take the form
• 2.add 3 labels,3 textboxes,1 button control
• private void button1_Click(object sender, EventArgs e)
• { textBox3.Text = textBox1.Text + textBox2.Text; }
• o/p:1010
• it gives concatenation error
• ex:
• "10"+"10"=1010
• 10+10=20;
• we can overcome this problem using parsing method..
• textBox3.Text = (int.Parse(textBox1.Text)
+int.Parse(textBox2.Text)).ToString();
• 2 nd method:
• private void button1_Click(object sender, EventArgs e)
• { // textBox3.Text =
(int.Parse(textBox1.Text)
+int.Parse(textBox2.Text)).ToString();
• int a, b, c;
• a = int.Parse(textBox1.Text);
• b = int.Parse(textBox2.Text);
• c = a + b;
• textBox3.Text = c.ToString();
• }
• Working with converting method:
• working with convert class is called as converting.
• convert is the part fcl(frame work class library)
• convert is the collection of predefined methods
• convert.toint16()-short-2 bytes
• convert.toint32()-int-4 bytes
• convert.toint64()-long-8 bytes
• convert.tochar()
• convert.tobyte()
• convert.toboolean()
• convert.tofloat()
• convert.todouble()
• Example on converting:
• take the form
• 2.add 3 labels,3 textboxes,1 button control
• private void button1_Click(object sender, EventArgs e)
• { textBox3.Text = textBox1.Text + textBox2.Text; }
• o/p:1010
• it gives concatenation error
• ex:"10"+"10"=1010
• 10+10=20;
• we can overcome this problem using parsing method..
• textBox3.Text = (convert.toint32(textBox1.Text)
+convert.toint32(textBox2.Text)).ToString();
• 2 nd method:
• private void button1_Click(object sender, EventArgs e)
• {
• // textBox3.Text = (int.Parse(textBox1.Text)
+int.Parse(textBox2.Text)).ToString();
• int a, b, c;
• a = convert.toint16(textBox1.Text);
• b = convert.toint16(textBox2.Text);
• c = a + b;
• textBox3.Text = c.ToString();
• }
For more visit our website www.siri-kt.blogspot.com
Thanks for
Watching
More Angular JS TutorialsMore C sharp (c#) tutorials

More Related Content

What's hot

Object oriented programming 9 expressions and type casting in c++
Object oriented programming 9 expressions and type casting in c++Object oriented programming 9 expressions and type casting in c++
Object oriented programming 9 expressions and type casting in c++Vaibhav Khanna
 
Computer data type and Terminologies
Computer data type and Terminologies Computer data type and Terminologies
Computer data type and Terminologies glyvive
 
5variables in c#
5variables in c#5variables in c#
5variables in c#Sireesh K
 
SHA- Secure hashing algorithm
SHA- Secure hashing algorithmSHA- Secure hashing algorithm
SHA- Secure hashing algorithmRuchi Maurya
 
Aes128 bit project_report
Aes128 bit project_reportAes128 bit project_report
Aes128 bit project_reportNikhil Gupta
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 

What's hot (14)

Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
 
Learning python
Learning pythonLearning python
Learning python
 
Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
 
MD-5 : Algorithm
MD-5 : AlgorithmMD-5 : Algorithm
MD-5 : Algorithm
 
C Omega
C OmegaC Omega
C Omega
 
30csharp
30csharp30csharp
30csharp
 
Object oriented programming 9 expressions and type casting in c++
Object oriented programming 9 expressions and type casting in c++Object oriented programming 9 expressions and type casting in c++
Object oriented programming 9 expressions and type casting in c++
 
Computer data type and Terminologies
Computer data type and Terminologies Computer data type and Terminologies
Computer data type and Terminologies
 
SHA 1 Algorithm
SHA 1 AlgorithmSHA 1 Algorithm
SHA 1 Algorithm
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
SHA- Secure hashing algorithm
SHA- Secure hashing algorithmSHA- Secure hashing algorithm
SHA- Secure hashing algorithm
 
MD5
MD5MD5
MD5
 
Aes128 bit project_report
Aes128 bit project_reportAes128 bit project_report
Aes128 bit project_report
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 

Similar to 19csharp

Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Sónia
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ toolAbdullah Jan
 
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
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxRonaldo Aditya
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.pptFatimaZafar68
 
Getting started cpp full
Getting started cpp   fullGetting started cpp   full
Getting started cpp fullVõ Hòa
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
 
Learning python
Learning pythonLearning python
Learning pythonFraboni Ec
 
Learning python
Learning pythonLearning python
Learning pythonJames Wong
 
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
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 

Similar to 19csharp (20)

Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
What is Data Types and Functions?
What is Data Types and Functions?What is Data Types and Functions?
What is Data Types and Functions?
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
 
Getting started cpp full
Getting started cpp   fullGetting started cpp   full
Getting started cpp full
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Learning python
Learning pythonLearning python
Learning python
 
Learning python
Learning pythonLearning python
Learning python
 
Learning python
Learning pythonLearning python
Learning python
 
Learning python
Learning pythonLearning python
Learning python
 
Learning python
Learning pythonLearning python
Learning python
 
Learning python
Learning pythonLearning python
Learning python
 
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)
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Data types in c++
Data types in c++ Data types in c++
Data types in c++
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 

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

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
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
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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"
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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"
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

19csharp

  • 2. • we can convert one datatype into different datatypes. • it is classified into 2 types • 1.implicit type casting • 2.explicit type casting • 1.implicit type casting: • In this we convert lower datatypes are converts into higher data types.it is also called as internal type casting. It is under control of clr; • using System; • namespace implicittypecastin_exm • { class Program • { static void Main(string[] args) • { int i = 545454;//4 bytes • long l = i;//8 bytes • Console.WriteLine("the long value is:" + l.ToString()); • Console.ReadLine(); • } } }
  • 3. • 2.Explicit type casting: • In this we convert higher datatypes converts into lower datatypes. it is also called as external type casting. this is under control of the programmer • using System; • namespace implicittypecastin_exm • { class Program • { static void Main(string[] args) • { long l = 454545454;//8 bytes • int i = l;//4 bytes • Console.WriteLine("the int value is:" + i.ToString()); • Console.ReadLine(); • } } } • the above example gives error. cant implicit convert higher to lower datatypes. we can overcome this problem.explit type casting classified into
  • 4. • 3 types : • 1.c++ style type casting • 2.parsing • 3.converting • 1.c++ style type casting: • in this type casting higher datatypes are converts into lower datatypes. • ex: • long l = 454545454;//8 bytes • int i =(int) l;//4 bytes • Console.WriteLine("the int value is:" + i.ToString()); • Console.ReadLine(); • 2.working with parsing: • as .net all the datatypes are predefined structures. • int i; • int-structure • i-structure variable.
  • 5. C# Type Conversion Methods C# provides the following built-in type conversion methods: Methods & Description ToBoolean Converts a type to a Boolean value, where possible. ToByte Converts a type to a byte. ToChar Converts a type to a single Unicode character, where possible. ToDateTime Converts a type (integer or string type) to date-time structures. ToDecimal Converts a floating point or integer type to a decimal type. ToDouble Converts a type to a double type. ToInt16 Converts a type to a 16-bit integer. ToInt32 Converts a type to a 32-bit integer.
  • 6. ToInt64 Converts a type to a 64-bit integer. ToSbyte Converts a type to a signed byte type. ToSingle Converts a type to a small floating point number. ToString Converts a type to a string. ToType Converts a type to a specified type. ToUInt16 Converts a type to an unsigned int type. ToUInt32 Converts a type to an unsigned long type. ToUInt64 Converts a type to an unsigned big integer.
  • 7. • structure is a collection of predefined methods • 1.minvalue() • 2.maxvalue() • 3.tostring() • 4.parse() • working with parse() is called as parsing. parse() method can be used only to convert from strings into int. tostring() can be used only to convert from int to string. • ex: print the limits of datatypes. • 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.ReadLine(); }
  • 8. • 2.example on parsing • 1.take the form • 2.add 3 labels,3 textboxes,1 button control • private void button1_Click(object sender, EventArgs e) • { textBox3.Text = textBox1.Text + textBox2.Text; } • o/p:1010 • it gives concatenation error • ex: • "10"+"10"=1010 • 10+10=20; • we can overcome this problem using parsing method.. • textBox3.Text = (int.Parse(textBox1.Text) +int.Parse(textBox2.Text)).ToString();
  • 9. • 2 nd method: • private void button1_Click(object sender, EventArgs e) • { // textBox3.Text = (int.Parse(textBox1.Text) +int.Parse(textBox2.Text)).ToString(); • int a, b, c; • a = int.Parse(textBox1.Text); • b = int.Parse(textBox2.Text); • c = a + b; • textBox3.Text = c.ToString(); • }
  • 10. • Working with converting method: • working with convert class is called as converting. • convert is the part fcl(frame work class library) • convert is the collection of predefined methods • convert.toint16()-short-2 bytes • convert.toint32()-int-4 bytes • convert.toint64()-long-8 bytes • convert.tochar() • convert.tobyte() • convert.toboolean() • convert.tofloat() • convert.todouble()
  • 11. • Example on converting: • take the form • 2.add 3 labels,3 textboxes,1 button control • private void button1_Click(object sender, EventArgs e) • { textBox3.Text = textBox1.Text + textBox2.Text; } • o/p:1010 • it gives concatenation error • ex:"10"+"10"=1010 • 10+10=20; • we can overcome this problem using parsing method.. • textBox3.Text = (convert.toint32(textBox1.Text) +convert.toint32(textBox2.Text)).ToString();
  • 12. • 2 nd method: • private void button1_Click(object sender, EventArgs e) • { • // textBox3.Text = (int.Parse(textBox1.Text) +int.Parse(textBox2.Text)).ToString(); • int a, b, c; • a = convert.toint16(textBox1.Text); • b = convert.toint16(textBox2.Text); • c = a + b; • textBox3.Text = c.ToString(); • }
  • 13. For more visit our website www.siri-kt.blogspot.com Thanks for Watching More Angular JS TutorialsMore C sharp (c#) tutorials