Passing C # parameter value

I use contactsreader.dllto import Gmail contacts. One of my methods has a parameter out. I'm doing it:

Gmail gm = new Gmail();
DataTable dt = new DataTable();
string strerr;
gm.GetContacts("chendur.pandiya@gmail.com", "******", 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 the parameters out?

+5
source share
5 answers

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

bool isOk;
DataTable dtContact;
string strError;
gm.GetContacts("chendur.pandiya@gmail.com", "******",
    out isOk, out dtContact, out strError);

In other words, you do not pass values ​​to these parameters, they get them on the way out. Only one way.

+6
source

When calling the method, you should output "out" - gm.GetContacts("chendur.pandiya@gmail.com", "******", out yourOK, out dt, out strerr);

, , DataTable dt = new DataTable(); . , GetContacts out.

MSDN.

+2

, ...

public class Program
{
    static void Method(out string param)
    {
    param = "Beautifull Bangladesh";
    }
    static void Main()
    {
        string valueOut;
        Method(out valueOut);

        Console.WriteLine(valueOut);
        Console.ReadKey();
   }
}
+2

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

, out,

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

, out , . out - MSDN.

+1

, bool out .

bool boolIsOK = true;
gm.GetContacts("chendur.pandiya@gmail.com", "******", out boolIsOK, out dt, out strerr)
0

All Articles