Good Day Group,
Recently I started a small test project in C# VS 05 for learning
purposes. I have a class and a form. I defined a property in a class
with get/set and create an instance of class1 on form.
The part I'm confused at is when trying to access Name property
outside the click event it wouldn't work. Why is that? Should I
create an instance after the InitializeComponent? and move all
constants & variables to class1. I'd appreciate some feedback.
Thanks
Ian
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Class1 Testc = new Class1(); // create a new instance
string sCompany = "";
const string sDATABASE;
const string sUSERID;
Testc.???? //>cann't access property Name here
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Testc.Name = "abc"; //>can access property Name here
}
}
class Class1
{
private String name;
public String Name
{
get
{
return _name;
}
set
{
name = value;
}
}
}
}