Using checked and unchecked. : Data Type Cast « Data Type « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / CSharp Tutorial » Data Type » Data Type Cast 
2. 49. 17. Using checked and unchecked.
 
 
using System; 
 
class MainClass {  
  public static void Main() {  
    byte a, b; 
    byte result; 
 
    a = 127
    b = 127
  
    try {  
      result = unchecked((byte)(a * b))
      Console.WriteLine("Unchecked result: " + result)
 
      result = checked((byte)(a * b))// this causes exception 
      Console.WriteLine("Checked result: " + result)// won't execute 
    }  
    catch (OverflowException exc) {  
      // catch the exception  
      Console.WriteLine(exc)
    }  
  }  
}

        
Unchecked result: 1
System.OverflowException: Arithmetic operation resulted in an overflow.
   at MainClass.Main()
  
2. 49. Data Type Cast
2. 49. 1. Type Conversion in Expressions
2. 49. 2. Automatic Conversions
2. 49. 3. The use of the cast operator: how information loss can occur when explicitly converting a variable of one type to another
2. 49. 4. Automatic conversion from long to double
2. 49. 5. Cast an int into a double
2. 49. 6. Cast an int into a byte, no data lost
2. 49. 7. Cast an int into a byte, data lost
2. 49. 8. Cast a uint into a short, no data lost
2. 49. 9. Cast a uint into a short, data lost
2. 49. 10. Cast a long into a uint, no data lost
2. 49. 11. cast a long into a uint, data lost
2. 49. 12. Cast an int into a char
2. 49. 13. Cast byte back for byte calculation
2. 49. 14. Using casts in an expression.
2. 49. 15. Conversions of numeric types: checked and unchecked conversions
2. 49. 16. Conversions of numeric types: checked conversions block
2. 49. 17. Using checked and unchecked.
2. 49. 18. Using checked and unchecked with statement blocks.
2. 49. 19. Most significant bits lost
2. 49. 20. Raises the OverflowException exception
2. 49. 21. Get Type Code after casting
w__w_w__.ja_va_2___s__.c__o___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.