Declare a member inside the class and assign the value that you passed to the member inside the constructor:
class Checks
{
private string hostname2;
public Checks(string hostname2)
{
this.hostname2 = hostname2;
}
public void Testing()
{
MessageBox.Show(hostname2);
}
}
If you also need external access, do this property:
class Checks
{
public string Hostname2 { get; set; }
public Checks(string hostname2)
{
this.Hostname2 = hostname2;
}
public void Testing()
{
MessageBox.Show(Hostname2);
}
}
Properties start with a capital letter by convention. Now you can access it as follows:
Checks c = new Checks("hello");
string h = c.Hostname2;
Andy : , , setter private:
public string Hostname2 { get; private set; }