As has been said, the C# equivalent of a VB procedure (Sub) is a function with a void return type. Also, the C# equivalent of a VB module is a static class.
I'd be inclined to use a boolean function in this case though:That combines validation and returning the result with displaying the error message if it fails. What it doesn't do is give you the numeric value, which is the problem with centralised validation like that. You can't get an integer and a boolean returned. That's why TryParse has the number passed by reference, but if you were going to try that yourself then you may as well just use TryParse directly each time.C# Code:
public bool ValidateInteger(string val) { bool result = false; int number; if (int.TryParse(val, number)) { result = true; } else { MessageBox.Show("Please enter an integer value", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return result; }




Reply With Quote