How to convert an Integer to Hexadecimal string in C# ?

You can easily format an integer to an Hexadecimal string in C# using the ToString() method.

Below is a sample sourcecode that demonstrates How to convert an Integer to Hexadecimal string in C# ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    static class Program
    {
        static void Main()
        {
            FormatString();           
        }  
        static void FormatString()
        {
            int intVal = 9;        
            string formattedString = intVal.ToString("X");
            MessageBox.Show(formattedString); 

        }
    }  
}

Leave Your Comment