【发布时间】:2021-05-18 07:52:31
【问题描述】:
如何从其他方法分配给列表?我创建了 WPF 应用程序。
我试过了:
private static Random number = new Random();
private void count()
{
int maxfirst = 10;
int maxsecond = 10;
int secondc = number.Next(2, maxsecond);
int firstc = number.Next(1, maxfirst);
if (mark.Text == "+")
{
total = (firstc + secondc);
}
else if (mark.Text == "-")
{
total = (firstc - secondc);
}
else if (mark.Text == "*")
{
total = (firstc * secondc);
}
else
{
firstc = secondc * number.Next(1, maxfirst / secondc);
int residue = (firstc % secondc);
if (residue == 0)
{
total = (firstc / secondc);
}
}
firstt.Text = firstc.ToString();
secondt.Text = secondc.ToString();
result.Text = total.ToString();
}
我有另一种方法:
List<string> list = new List<string> { result.Text, "2", "3" };
我怎样才能获得足够的 result.Text 来列出?它写信给我:编译器错误 CS0236-A 字段初始化程序无法引用非静态字段、方法或属性“字段”。
感谢您的建议和时间。
【问题讨论】: