Sabari M Sabari M
Updated date Feb 22, 2021
This code snippet helps you to understand how to convert char into an int in C# (C sharp).

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

ABOUT THE AUTHOR

Sabari M
Sabari M
Software Professional, India

IT professional with 14+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.techieclues.com/profile/alagu-mano-sabari-m

Comments (0)

There are no comments. Be the first to comment!!!
×