User Tools

Site Tools


notes:csharp:parsing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:csharp:parsing [2016/03/11]
admin
notes:csharp:parsing [2016/12/13] (current)
admin
Line 1: Line 1:
 ====== Parsing and Casting in C# ====== ====== Parsing and Casting in C# ======
  
-//​Parse// ​should be used if you are certain the parsing will succeed. ​In this casean exception denotes an error in the application. ​//​TryParse// ​should be used if you are not sure that the parsing will succeed.+Use the //​Parse// ​method ​if you are certain the parsing will succeed. ​Otherwiseuse //​TryParse//​.
  
-The difference between //​Parse/​TryParse//​ and //Convert// is that //​Convert// ​enables ​//null// values. It doesn'​t throw an //​ArgumentNullException//;​ instead, it returns the default value for the supplied type. Also, //Parse// takes only a string as its input, while //Convert// accepts other types.+The difference between //​Parse/​TryParse//​ and //Convert// is that //​Convert// ​allows ​//null// values. It doesn'​t throw an //​ArgumentNullException//;​ instead, it returns the default value for the supplied type. Also, //Parse// takes only a string as its input, while //Convert// accepts other types.
  
  
Line 39: Line 39:
 The implicit and explicit operators should be declared as public static methods. The implicit and explicit operators should be declared as public static methods.
  
-**Example**: Define the following custom casting in the Point3D type:+Example: Define the following custom casting in the Point3D type:
  
   * narrowing casting (from Point3D to Point 2D) using the //explicit operator// ​   * narrowing casting (from Point3D to Point 2D) using the //explicit operator// ​
notes/csharp/parsing.txt ยท Last modified: 2016/12/13 by admin