This code snippet helps you to understand how to convert char into an int in C# (C sharp).
Using Char.GetNumericValue Method
using System;
namespace SampleApp
{
class ConvertChartoInt
{
public static void Main()
{
char chr = '2';
int integerValue = (int)Char.GetNumericValue(chr);
Console.WriteLine(integerValue);
Console.ReadKey();
}
}
}
Output:
2
Using Int32.Parse Method
using System;
namespace SampleApp
{
class ConvertChartoInt
{
public static void Main()
{
char chr = '2';
int integerValue = int.Parse(chr.ToString());
Console.WriteLine(integerValue);
Console.ReadKey();
}
}
}
Output:
2
Comments (0)