初学者的c#课题

l--*_*''' 1 c#

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void txtTestPrime_Click(object sender, EventArgs e)
        {
            TestPrime myNumber = new TestPrime();
            lblAnswer.Text = 
                myNumber.TestPrime(ToInt16(txtTestPrime.Text)) ? "it is prime!" : "it is NOT prime!";
        }

    }
    public class TestPrime(int number)
    {
        bool prime;


    }
Run Code Online (Sandbox Code Playgroud)

它不喜欢这一行:

public class TestPrime(int number)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:无效的标记'('在类,结构或接口成员声明中

expect { and ;走上了那条线

也在这一行:

myNumber.TestPrime(ToInt16(txtTestPrime.Text)) ? "it is prime!" : "it is NOT prime!"; 
Run Code Online (Sandbox Code Playgroud)

我得到错误4'WindowsFormsApplication1.TestPrime'不包含'TestPrime'的定义,并且没有可以找到接受类型'WindowsFormsApplication1.TestPrime'的第一个参数的扩展方法'TestPrime'(你是否缺少using指令或程序集引用?)

也许这是我做错的一件大事.请帮忙!

Ben*_*igt 7

TestPrime认为是一类?这听起来更像是一个函数(也称为"方法").

尝试将该行更改为

public static bool TestPrime(int number)
Run Code Online (Sandbox Code Playgroud)