String方法的C#类构造

时间:2017-01-12 18:09:13

标签: c# string class constructor

我有一个有几种方法的课。

这是我的函数映射:

    public void Connect(string SourceFile, OleDbConnection Connection, OleDbCommand Command) { zConnect(SourceFile, Connection, Command); }
    public void Tablenames2cmb(OleDbConnection Connection, ComboBox TargetComboBox) { zTablenames2cmb(Connection, TargetComboBox); }
    public void Tablenames2cmb(OleDbConnection Connection, string Exclusion, ComboBox TargetComboBox) { zTablenames2cmb(Connection, Exclusion, TargetComboBox); }
    public string GetUser(OleDbConnection Connection, OleDbCommand Command, OleDbDataReader Reader, string username) { zGetUser(Connection, Command, Reader, username); }

前3种方法编译得很好。但是字符串方法给了我一个没有回复的错误。

方法:

    private string zGetUser(OleDbConnection Connection, OleDbCommand Command, OleDbDataReader Reader, string username)
    {
        string result = "Foo";
        return result;
    }

我想我在函数映射中犯了一个愚蠢的错误,但我无法弄清楚它是什么。

3 个答案:

答案 0 :(得分:2)

您的方法需要返回它调用的方法的值:

public string GetUser(OleDbConnection Connection, OleDbCommand Command, OleDbDataReader Reader, string username)
{ 
   return zGetUser(Connection, Command, Reader, username); 
}

答案 1 :(得分:2)

你可能错过了返回声明

public string GetUser(OleDbConnection Connection, OleDbCommand Command, OleDbDataReader Reader, string username) { return zGetUser(Connection, Command, Reader, username); }

答案 2 :(得分:2)

您不从GetUser方法返回字符串。它的身体没有回报价值:

public string GetUser(OleDbConnection Connection, OleDbCommand Command, OleDbDataReader Reader, string username) 
{ 
   return zGetUser(Connection, Command, Reader, username); 
}

有时候,不那么聪明的格式会有所帮助。