我需要从static[webmethod]
调用非静态方法。它没有得到调用,我使用breakpoint来测试它。我试图通过给类实例来调用它。 这就是我想要的。如何从静态方法调用非静态方法
[WebMethod]
public static string get_runtime_values(string get_ajax_answer_title,string get_ajax_answer_des)
{
if (get_ajax_answer_title.Equals("") && (get_ajax_answer_title.Equals("")))
{
return "null";
}
else
{
int got_question_id = getting_question_id;
DataHandler.breg obj = new DataHandler.breg();
obj.add_anwers(got_question_id, get_ajax_answer_title, get_ajax_answer_des);
return "inserted";
}
querystring object_new = new querystring();
object_new.show();
}
查询字符串是类更换预定控制的名字进入,当且根据输入else语句,但之后它直接拿到跳out.Moreover当我将鼠标悬停在查询字符串,它说
Unreachable code detected.
我该怎么做才能使它工作?
你有两个'if'和'else'部分......你永远也做不到的下一行 – freefaller
也是'return':更换'如果(get_ajax_answer_title.Equals( “”)&&( get_ajax_answer_title.Equals(“”)))''with'if(get_ajax_answer_title.Equals(“”)&&(get_ajax_answer_des.Equals(“”))' –
你可以在发布这个问题之前用google搜索这个问题,它会节省每一次SO.this应该帮助http://stackoverflow.com/questions/1360183/call-non-static-method-from-static-method-c-sharp。 – ankur