Search This Blog

Sunday, 6 August 2017

How to convert char to int?

C# Code

Char.GetNumericValue Method Converts a specified numeric Unicode character to a double-precision floating-point number.

int result = (int)Char.GetNumericValue('1');
// Output
// result = 1

FYI,

Note: Below statement treats the argument as char and returns its ascii value. It is returning the ASCII value of character 1.

int result1 = Convert.ToInt32('1');
// Output
// result = 49

Note: Below statement treats the argument as string and converts the value into Int.

int result1 = Convert.ToInt32("1");
// Output
// result = 1

No comments:

Post a Comment

Elasticsearch - Nodes, clusters, and shards

Elastic Stack Video - Load your gun in short time.   Beginner's Crash Course to Ela...

Recent Post