I’m having trouble running a method in my program.cs
For example, this is in my program.cs:
public string tryConn(string address, string name, string password)
{
string connString = (address + ':' + name + ';' + password);
try
{
connect(connString);
return true;
}
catch
{
return false;
}
}
And on a form, within a buttons _Click method, I’m trying to run this function like this:
private void button1_Click(object sender, EventArgs e)
{
bool _conn = WindowsFormsApplication1.Program.tryConn('127.0.0.1','root','toor')
}
It’s simply just not having any of it, can anyone describe the steps I’d take to be able to get this to work?
You need to make tryConn
staticmethod to call it with class. You can read more about static class and static methods over here.