First, you need to change the name of your class. " Process " is the name of the class in the class library and is likely to cause confusion for anyone reading your code.
Suppose for the rest of this answer you changed the class name to MyProcessor (still a bad name, but not a well-known, commonly used class.)
In addition, you do not have enough code to verify that user input is indeed a number from 0 to 9. This is necessary in the form code, and not in the class code.
- Assuming TextBox is named textBox1 (VS is generated by default for the first TextBox added to the form)
- Further, provided that the name of the button is button1
In Visual Studio, double-click the button to create a button click event handler that looks like this:
protected void button1_Click(object sender, EventArgs e) { }
Inside the event handler, add code so that it looks like this:
protected void button1_Click(object sender, EventArgs e) { int safelyConvertedValue = -1; if(!System.Int32.TryParse(textBox1.Text, out safelyConvertedValue)) {
A class with an established access rule should look like this:
namespace addTen { public class MyProcessor { public int AddTen(int num) { return num + 10; } } }
David
source share