簡體   English   中英

字符串方法的C#類構造

[英]C# Class construction for String Method

我有一堂課,有幾種方法。

這是我的函數映射:

    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); }

前三種方法可以編譯。 但是字符串方法給了我一個錯誤,那就是沒有回報。

方法:

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

我想我在函數映射方面犯了一個愚蠢的錯誤,但是我不知道它是什么。

您的方法需要返回其調用的方法的值:

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

您可能在這里錯過了退貨聲明

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

您不會從方法GetUser返回字符串。 它的主體沒有返回值:

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

有時,不太聰明的格式化會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM