Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Classes
Message
From
16/06/2003 20:49:35
 
 
To
16/06/2003 20:40:51
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00800616
Message ID:
00800619
Views:
18
This message has been marked as the solution to the initial question of the thread.
Alvin,

You can instantiate it at the beginning of your code when you define it and all other objects on the form, if you want to. Like this:
private MyClass oClass = new MyClass();
or you might choose just to define it there and instantiate it elsewhere, like in the constructor or in the form's Load() event. So, in that case you'd have:
private MyClass oClass;

// then instantiate it later:
this.oClass = new MyClass();
Then, when you need to access it in any other methods, just do it:
this.oClass.SomeMethod();
// or maybe
this.oClass.SomeProperty = "something";
HTH,
~~Bonnie



>Hi,
>
>I have a class that I want to instantiate only once in a method on the form, but I want to be able to access the instance of this class from multiple methods on the form. Is this possible? How?
>
>I hope this is not too vague.
>
>Anyway,
>
>Where could I instantiate the class if I want this type of behaviour?
>
>I am trying to figure out how classes, access modifiers work together. It's funny how reading it makes some sense but trying to code something is not so easy.
>
>Help if you can,
>
>Thanks,
>
>Alvin
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform