Forums - C# Corner

Forum guidelines
Violeta Popa

Violeta Popa

  • 1.2k
  • 137
  • 87.9k

variable is assigned but never used

Apr 9 2013 4:57 PM
Hi..what's wrong with this code? I declared the variable pret, and then used it, but i'm informed that is assigned but never used.

     when   form load{     
double pret;// it's assigned but never used
            if (cnp.StartsWith("1") || cnp.StartsWith("2"))
            {
                string an = "19" + cnp.Substring(1, 2);
                string luna = cnp.Substring(3, 2);
                string zi = cnp.Substring(5, 2);
                string data_nastere = luna + "/" + zi + "/" + an;

                DateTime data = Convert.ToDateTime(data_nastere);
                TimeSpan zile = DateTime.Today.Subtract(data);
                varsta = Convert.ToInt32(zile) / 356;
                if (varsta <= 23)
                {
                    if (double.Parse(tb2.Text) <= 1200)
                        pret = 340;
                    else if (double.Parse(tb2.Text) >= 1201 && double.Parse(tb2.Text) <= 1600)
                        pret = 486;
                    else if (double.Parse(tb2.Text) >= 1601 && double.Parse(tb2.Text) <= 2000)
                        pret = 535;
                    else if (double.Parse(tb2.Text) >= 2001 && double.Parse(tb2.Text) <= 2400)
                        pret = 583;
                    else if (double.Parse(tb2.Text) >= 2401 && double.Parse(tb2.Text) <= 3000)
                        pret = 729;
                    else if (double.Parse(tb2.Text) <= 3001)
                        pret = 1458;
                }
}

Answers (1)

Unlimited Flat-Free License

SPONSORED BY

File APIs for .NET
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!