Click here to Skip to main content
15,881,757 members
Home / Discussions / C#
   

C#

 
GeneralRe: I need help pls!! - live radio station Pin
cristiansje1-Feb-04 8:49
cristiansje1-Feb-04 8:49 
GeneralUpdateCommandUI in C# and .NET Pin
dabs31-Jan-04 16:53
dabs31-Jan-04 16:53 
GeneralRe: UpdateCommandUI in C# and .NET Pin
Mazdak31-Jan-04 23:33
Mazdak31-Jan-04 23:33 
GeneralRe: UpdateCommandUI in C# and .NET Pin
Uwe Keim1-Feb-04 1:39
sitebuilderUwe Keim1-Feb-04 1:39 
GeneralRe: UpdateCommandUI in C# and .NET Pin
Mazdak1-Feb-04 1:56
Mazdak1-Feb-04 1:56 
GeneralAdobe Acrobat ocx problem Pin
Alex Korchemniy31-Jan-04 16:21
Alex Korchemniy31-Jan-04 16:21 
QuestionAutomatically creating classes ? Pin
Andres Coder31-Jan-04 13:27
Andres Coder31-Jan-04 13:27 
AnswerRe: Automatically creating classes ? Pin
Colin Angus Mackay31-Jan-04 15:39
Colin Angus Mackay31-Jan-04 15:39 
Create a singleton. Here's how:

Create a private static member variable of your class of the same type as your class and call it singleInstance or similar.

Create a static initialiser which is like a normal constructor but with the keyword static in front of it. In this method create a new instance of the class and assign it to the singleInstance member variable.

Modify your constructor so that it is private. This ensures that no one else can create your class.

Create a new static public get property called Instance or similar and return the singleInstance member variable.

The remainder of the class is as you would normally have it.

You have now created a singleton. Every time you want to use the class you access it through the Instance property. This version of a singleton will be created at application start up.

If you want to delay the initialisation until first use then you can remove the static initialiser and have the code for the Instance property check singleInstance == null in which case a new instance of the class is created and assigned to singleInstance first. Then it returns singleInstance as it did before.

Does this help?

--Colin Mackay--

EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar


GeneralRe: Automatically creating classes ? Pin
Andres Coder31-Jan-04 21:35
Andres Coder31-Jan-04 21:35 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 1:28
Colin Angus Mackay1-Feb-04 1:28 
GeneralRe: Automatically creating classes ? Pin
Andres Coder1-Feb-04 2:57
Andres Coder1-Feb-04 2:57 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 3:42
Colin Angus Mackay1-Feb-04 3:42 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu1-Feb-04 9:05
Arjan Einbu1-Feb-04 9:05 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 9:48
Colin Angus Mackay1-Feb-04 9:48 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu1-Feb-04 22:04
Arjan Einbu1-Feb-04 22:04 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay2-Feb-04 1:33
Colin Angus Mackay2-Feb-04 1:33 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu2-Feb-04 3:26
Arjan Einbu2-Feb-04 3:26 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay2-Feb-04 4:08
Colin Angus Mackay2-Feb-04 4:08 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu2-Feb-04 4:36
Arjan Einbu2-Feb-04 4:36 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 1:35
Colin Angus Mackay1-Feb-04 1:35 
GeneralRe: Automatically creating classes ? Pin
Andres Coder1-Feb-04 4:47
Andres Coder1-Feb-04 4:47 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 5:01
Colin Angus Mackay1-Feb-04 5:01 
QuestionVirtual colums in a datagrid? Pin
Franz Pentenrieder31-Jan-04 12:02
Franz Pentenrieder31-Jan-04 12:02 
AnswerRe: Virtual colums in a datagrid? Pin
Heath Stewart2-Feb-04 4:21
protectorHeath Stewart2-Feb-04 4:21 
GeneralQuick answer for threading Pin
jacal9931-Jan-04 11:35
jacal9931-Jan-04 11:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.