Cannot convert null to 'int' because it is a value type--need help

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi, i need some advice regarding the code that i have created,

<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% Code Snippet

  <font size=2> public static int IntToHex(int no)
        {
            try
            {
                string hex = no.ToString("x2");
                return Convert.ToInt32(hex);
            }
            catch (OverflowException ofe)
            {
                Console.WriteLine("{0}",ofe.StackTrace);
                return null;

            }
            catch (StackOverflowException soe)
            {
                Console.WriteLine("{0}", soe.StackTrace);
                return null;
           
            }
       
        }</font>

the error that is shown on the compiler is:

Cannot convert null to int because it is a value type

any advice is appreciated .thanks in advance


View the full article
 
Back
Top