Search code examples
c#parametersout

C# out parameter value passing


I am using contactsreader.dll to import my Gmail contacts. One of my method has the out parameter. I am doing this:

Gmail gm = new Gmail();
DataTable dt = new DataTable();
string strerr;
gm.GetContacts("[email protected]", "******", true, dt, strerr);
// It gives invalid arguments error..

And my Gmail class has

public void GetContacts(string strUserName, string strPassword,out bool boolIsOK,
out DataTable dtContatct, out string strError);

Am I passing the correct values for out parameters?


Solution

  • You need to pass them as declared variables, with the out keyword:

    bool isOk;
    DataTable dtContact;
    string strError;
    gm.GetContacts("[email protected]", "******",
        out isOk, out dtContact, out strError);
    

    In other words, you don't pass values to these parameters, they receive them on the way out. One way only.