TechieClues TechieClues
Updated date Feb 22, 2021
This code snippet helps you to understand how to convert char into an int in C# (C sharp).
  • 1.4k
  • 0
  • 0

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

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

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