Search code examples
c#parsingint64

Cannot convert long to int Issue in C#


In the below code i want to add 0 before the number (ie) if the number is 96333 it should be 096333 when i execute it i am facing issue cannot convert long to int.Pls help me to solve the issue.

  public FileDto GenerateBarcodeImage(Int64 BarCodeNumber)
    {
        //string s = BarCodeNumber.ToString().PadLeft(4, '0');
        string result = BarCodeNumber.ToString().PadLeft(4, '0');
        int sds = Int64.Parse(result);
        return GetBarcodeImage(sds);
    }

Solution

  • replace

    int sds = Int64.Parse(result);
    

    with

    long sds = Int64.Parse(result);