views:

154

answers:

4

I am using contactsreader.dll to import my gmail contacts... One of my method has 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...

+1  A: 

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.

David M
+1  A: 

You have to put "out" when calling the method - gm.GetContacts("[email protected]", "******", out yourOK, out dt, out strerr);

And by the way, you don't have to do DataTable dt = new DataTable(); before calling. The idea is that the GetContacts method will initialize your out variables.

Link to MSDN tutorial.

Petar Minchev
A: 

I would suggest that you pass a bool variable instead of a literal value and place the out keyword before them.

bool boolIsOK = true;
gm.GetContacts("[email protected]", "******", out boolIsOK, out dt, out strerr)
ChrisBD
A: 

Since the definition of your function

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

requires that you pass some out parameters, you need to respect the method signature when invoking it

gm.GetContacts("<username>", "<password>", out boolIsOK, out dtContatct, out strError);

Note that out parameters are just placeholders, so you don't need to provide a value before passing them to the metohd. You can find more information about out parameters on the MSDN website.

BladeWise