Question : Error: Cannot convert string to float.....

Hi,

I have a class as follows:
 public class Employees
    {
        public string grade;
        public Single salary;

        //Constructor
        public Employees(string empGrade, Single grossSalary)
        {
            //use this to qualify the fields name and salary
            this.grade = empGrade;
            this.salary = grossSalary;
        }

        //Tax calculating method
        public Single CalculateTax()
        {
            if (grade == "A")
            {
                return (Single)(salary * 0.25);
            }
            else
            {
                return (Single)(salary * 0.33);
            }


        }

    }

Now in my form, I call this class as:
 private void Tax_Click(object sender, EventArgs e)
        {
            Employees objEmp = new Employees(txtGrade.Text, (Single)txtGross.Text);

        }
When i compile,  I get error: Cannot convert type string  to float for the line (Single) txtGross.Text.
What could be the error?

Regards
MI

Answer : Error: Cannot convert string to float.....

you could also try


Single.Parse(txtGross.Text);
Random Solutions  
 
programming4us programming4us