Hey folks.
I've just took up a course in C# and so this is part of a homework. I've tried various attempts but to no avail and so I thought I'd ask on here.
I have been asked to write a class to verify if a valid double has been entered in a textbox on a form. Once the string is entered in the main class, another class will be called to convert the given string into a double and if conversion, validate that the converted value is within a given range. I have to write various methods with different parameters (overload). Here is my attempt below:
namespace Assignment_3
{
public class InputUtility
{
public static bool GetDouble(string stringToConvert, out double dblOutValue, double minLimit, double maxLimit)
{
if (double.TryParse(stringToConvert, out dblOutValue))
{
if ((dblOutValue >= minLimit) && (dblOutValue <= maxLimit))
{
return true;
}
}
return false;
}
public static bool GetDouble(string stringToConvert, out double dblOutValue, double minLimit)
{
if (double.TryParse(stringToConvert, out dblOutValue))
{
if ((dblOutValue >= minLimit))
{
return true;
}
}
return false;
}
public static bool GetDouble(string stringToConvert, out double dblOutValue)
{
if (double.TryParse(stringToConvert, out dblOutValue))
{
return true;
}
return false;
}
In my main form, I have a textbox called numText. Now when a user enters a number into this, I need it to initially be checked against the first and if parameters not applicable, the second method etc in the above namespace and class. If a valid input entry (ie. a double), I want the number to populate the numText.text field however if invalid, an error message to pop up.
I am happy with writing the error message etc but I'm just unsure how to cross reference the double entered by the user to another classname and the overloaded methods as above.
The class that the numText entry will be in is:-
private bool ReadAndValidatePrice(out double price)
Any suggestions?