"MikeAth via DotNetMonster.com" <fo***@DotNetMonster.com> a écrit dans le
message de news:
1e******************************@DotNetMonster.com...
I have two different classes and one instance of the Form.
I would like to access the members of the Form instance in both classes
without having to create a new instance in the other class, because that
would give me access to different members than in the first instance and
would not behave as one global object. How can I do that, any guess?
You need the Singleton design pattern.
public class MyClass
{
private static MyClass instance = null;
private MyClass() {}
public static MyClass Instance()
{
if (instance == null)
instance = new MyClass();
return instance;
}
}
Called from either form like this :
{
MyClass formUser = MyClass.Instance();
...
}
Joanna
--
Joanna Carter
Consultant Software Engineer