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

PPTX
Secure Hash Algorithm
PPTX
Java8 and Functional Programming
PPT
PDF
Welcome vibrant-technology-navimumbai
PPTX
Welcome vibrant-technology-navimumbai
PDF
PDF secrets - hiding & revealing secrets in PDF documents
PDF
Intake 37 4
Secure Hash Algorithm
Java8 and Functional Programming
Welcome vibrant-technology-navimumbai
Welcome vibrant-technology-navimumbai
PDF secrets - hiding & revealing secrets in PDF documents
Intake 37 4

What's hot (14)

PDF
Intake 37 6
PPTX
Learning python
PDF
Intake 37 5
PDF
MD-5 : Algorithm
PPT
C Omega
PPTX
30csharp
PPTX
Object oriented programming 9 expressions and type casting in c++
PPTX
Computer data type and Terminologies
PDF
SHA 1 Algorithm
PPTX
5variables in c#
PPTX
SHA- Secure hashing algorithm
PDF
Aes128 bit project_report
PPT
Stream Based Input Output
Intake 37 6
Learning python
Intake 37 5
MD-5 : Algorithm
C Omega
30csharp
Object oriented programming 9 expressions and type casting in c++
Computer data type and Terminologies
SHA 1 Algorithm
5variables in c#
SHA- Secure hashing algorithm
Aes128 bit project_report
Stream Based Input Output
Ad

Similar to 19c (20)

PPT
Introduction to C#
PPTX
CS4443 - Modern Programming Language - I Lecture (2)
PDF
C# Data Types and Comments_Lecture2_C#.pdf
PPTX
Core C# Programming Constructs, Part 1
PDF
C Sharp: Basic to Intermediate Part 01
PPTX
2 programming with c# i
PPT
Csharp4 operators and_casts
PPTX
data types in C-Sharp (C#)
PPTX
PDF
CSharpCheatSheetV1.pdf
PPTX
C# overview part 1
PDF
C# Language Overview Part I
PPTX
CSharp Language Overview Part 1
PPT
Introduction To C#
PPTX
Getting started with C# Programming
PDF
Dotnet programming concepts difference faqs- 3
PPTX
C# 101: Intro to Programming with C#
PDF
434090527-C-Cheat-Sheet. pdf C# program
PPT
C Language fundamentals hhhhhhhhhhhh.ppt
PPT
Presentatiooooooooooon00000000000001.ppt
Introduction to C#
CS4443 - Modern Programming Language - I Lecture (2)
C# Data Types and Comments_Lecture2_C#.pdf
Core C# Programming Constructs, Part 1
C Sharp: Basic to Intermediate Part 01
2 programming with c# i
Csharp4 operators and_casts
data types in C-Sharp (C#)
CSharpCheatSheetV1.pdf
C# overview part 1
C# Language Overview Part I
CSharp Language Overview Part 1
Introduction To C#
Getting started with C# Programming
Dotnet programming concepts difference faqs- 3
C# 101: Intro to Programming with C#
434090527-C-Cheat-Sheet. pdf C# program
C Language fundamentals hhhhhhhhhhhh.ppt
Presentatiooooooooooon00000000000001.ppt
Ad

More from Sireesh K (20)

PPTX
Cn10
PPTX
chanakya neeti
PPTX
chanakya neeti
DOCX
What is mvc
PPTX
PPTX
31cs
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
Cn10
chanakya neeti
chanakya neeti
What is mvc
31cs

Recently uploaded (20)

PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
20th Century Theater, Methods, History.pptx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
HVAC Specification 2024 according to central public works department
Weekly quiz Compilation Jan -July 25.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Introduction to pro and eukaryotes and differences.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Virtual and Augmented Reality in Current Scenario
Chinmaya Tiranga quiz Grand Finale.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
20th Century Theater, Methods, History.pptx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
FORM 1 BIOLOGY MIND MAPS and their schemes
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
HVAC Specification 2024 according to central public works department

19c

  • 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