将VB转换为C#并获取方法名称预期错误

时间:2018-02-18 23:04:20

标签: c# vb.net

我正在将一些代码从VB转换为C#,但是这样做我得到了 jo 的'方法名称预期'错误 - interviewID = int.Parse( jo ( “interviewID”));.错误回来了 - 'jo'是'变量'但是像'方法'一样使用。

这是原始的VB代码:

Private interviewID As Integer
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim sr As New System.IO.StreamReader(context.Request.InputStream)
    Dim line As String = sr.ReadToEnd()
    Dim jo As JObject = JObject.Parse(line)
    interviewID = CInt(jo("interviewID"))


    GetIntervieweeTableInfo();
    WriteCallback(context, interviewee);
End Sub

这里它被转换为C#:

 private int interviewID;
    public void ProcessRequest(HttpContext context)
    {
        System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream);
        string line = sr.ReadToEnd();
        JObject jo = JObject.Parse(line);
        interviewID = int.Parse(jo("interviewID"));


        GetIntervieweeTableInfo();
        WriteCallback(context, interviewee);
    }

我错过了什么?

1 个答案:

答案 0 :(得分:5)

VB中的{p> jo("interviewID")JObject类中调用indexer,在C#中使用方括号[]代替正常括号()

正确的代码应该是:

interviewID = int.Parse(jo["interviewID"]);