class Class1
{
string str = "12";
int result=Convert.ToInt32(str);
}错误提示说:字段初始值无法使用非静态字段方法或属性,但我看到别人类似的写法并没有错啊。。
请问应该如何修改?
谢谢!
{
string str = "12";
int result=Convert.ToInt32(str);
}错误提示说:字段初始值无法使用非静态字段方法或属性,但我看到别人类似的写法并没有错啊。。
请问应该如何修改?
谢谢!
int result = Convert.ToInt32(str);写在方法里
写一个方法
private void test()
{
string str = "12";
int result = Convert.ToInt32(str);
}
直接调用 test 就可以了。
代码没调试~自己测试下。