2014-03-24 44 views
0

不知怎的,我的一個類中的構造函數沒有找到參數... 有沒有人遇到過這個問題?建築找不到?

這裏是我的代碼,我如何我稱之爲:

MoveFiles類:

class MoveFiles 
{ 
    #region Variables 

    //Variables 
    public string strSrcPath, strDstPath, strFdrName, strNewDestFldrPath = ""; 
    Main frm = new Main(); 

    #endregion 

    #region Constructor 

    //Constructor - accepts the path and store the value 
    private void MoveFiles(string strSourcePath, string strDestPath, string strFldrName) 
    { 
     strSrcPath = strSourcePath; 
     strDstPath = strDestPath; 
     strFdrName = strFldrName; 
    } 

    #endregion  
    ETC.... 

那麼這裏就是我稱之爲:

//move the files based on the source path, destination path, and folder name 
MoveFiles moveFile = new MoveFiles(strSrcPath, strDestPath, strFoldrName); 
moveFile.StartMove(); 

我在那裏的地方我調用它給了我一個錯誤,構造函數不帶三個參數....

你有這樣的問題,你是如何解決它的? 還是我只是瞎了,有沒有真的在那裏?

+0

構造函數不應該有返回類型,並且如果你想從另一個類中調用它,它不得爲'private'。 – birryree

+1

您是否使用Visual Studio?我希望你的代碼有多少錯誤/警告,除了你試圖調用它的代碼外,還有什麼問題 – musefan

回答

6

通過public MoveFiles

+0

謝謝。我實際上就是這樣,今天早上它給了我一些奇怪的錯誤,比如「member modifier public必須在成員類型和名稱之前」。也許這只是超級挑剔? – user3302467

1

你的構造函數替換private void MoveFiles是私人

private void MoveFiles(string strSourcePath, string strDestPath, string strFldrName) 
{ 
..... 
} 

其更改爲公共的(也構造函數沒有返回類型):

public MoveFiles(string strSourcePath, string strDestPath, string strFldrName) 
{ 
..... 
} 
4

更改構造函數

public MoveFiles(string strSourcePath, string strDestPath, string strFldrName) 
{ 
    strSrcPath = strSourcePath; 
    strDstPath = strDestPath; 
    strFdrName = strFldrName; 
} 

private void表示這是實例方法,而不是構造函數。而構造函數沒有返回類型。

0

這可能是由於您所做的構造private,而不是publicprotected

0

除非你是從自身內部實例化類,你將無法爲重載的構造函數是私有的事實,改爲標記public。並刪除返回類型void

0

構造函數沒有返回類型。遠程的void

//Constructor - accepts the path and store the value 
private MoveFiles(string strSourcePath, string strDestPath, string strFldrName) 
{ 
    strSrcPath = strSourcePath; 
    strDstPath = strDestPath; 
    strFdrName = strFldrName; 
} 

還要注意,私有構造函數只能在同一個類中調用。你可能打算把這個公開。