Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
Questionhow can i add a bitmap to resource directory project by code? Pin
Sasuko22-May-06 2:47
Sasuko22-May-06 2:47 
AnswerRe: how can i add a bitmap to resource directory project by code? Pin
stancrm22-May-06 21:14
stancrm22-May-06 21:14 
QuestionInstallation Script [modified] Pin
mfc_surfer22-May-06 2:45
mfc_surfer22-May-06 2:45 
AnswerRe: Installation Script [modified] Pin
Nimit Patel22-May-06 3:30
Nimit Patel22-May-06 3:30 
QuestionC# : implement chat room in pocket pc Pin
Pentellcc22-May-06 2:31
Pentellcc22-May-06 2:31 
QuestionDo pocket pc support foreign language? Pin
Pentellcc22-May-06 2:24
Pentellcc22-May-06 2:24 
QuestionSingletons.. Pin
martin_hughes22-May-06 2:20
martin_hughes22-May-06 2:20 
AnswerRe: Singletons.. [modified] Pin
J4amieC22-May-06 2:55
J4amieC22-May-06 2:55 
Its important to get one distiction solid in your mind.

A singleton is a single instance of a clas.

So, you should write whatever class will be a singleton in the normal manner before starting. ie/

public class MySingleton
{
   private string someVar = "";

   private MySingleton()
   {
   }

   public string SomeVar
   {
     get{ return this.someVar; }
     set{ this.someVar = value; }
   }
}


Note this has instance variables/accessors. The other thing to note is that it has a private constructor only!! This stops new instances of being created for this object (except for within the code).

Now, the purpose of a singleton. If, for whatever reason makes sense for your application, there should only EVER be one instance of MySingleton it is a candidate for the Singleton pattern.

1 line change

public class MySingleton
{
   public static readonly MySingleton Current = new MySingleton();

   private string someVar = "";

   private MySingleton()
   {
   }

   public string SomeVar
   {
     get{ return this.someVar; }
     set{ this.someVar = value; }
   }
}


Now, in your app you could have:
MySingleton.Current.MyVar = "Hellow World";

For examples of Singleton use within the framework look at HttpContext.Current in the System.Web namespace.

Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour


-- modified at 8:56 Monday 22nd May, 2006
GeneralRe: Singletons.. [modified] Pin
martin_hughes22-May-06 8:55
martin_hughes22-May-06 8:55 
Questionexception Pin
Smitha Sondur22-May-06 2:14
Smitha Sondur22-May-06 2:14 
Questiona few important questions about forms ? help please ... Pin
cmpeng3422-May-06 2:03
cmpeng3422-May-06 2:03 
AnswerRe: a few important questions about forms ? help please ... Pin
Dustin Metzgar22-May-06 5:46
Dustin Metzgar22-May-06 5:46 
QuestionFind Button Pin
alwz_nikhil22-May-06 1:43
alwz_nikhil22-May-06 1:43 
AnswerRe: Find Button Pin
CodyGen22-May-06 4:44
CodyGen22-May-06 4:44 
Questionprinting unicode characters on Console [modified] Pin
cshivaprasad22-May-06 1:43
cshivaprasad22-May-06 1:43 
AnswerRe: printing unicode characters on Console [modified] Pin
stancrm22-May-06 3:53
stancrm22-May-06 3:53 
QuestionFileStream in c# Pin
H he el el oooo22-May-06 1:26
H he el el oooo22-May-06 1:26 
AnswerRe: FileStream in c# Pin
Colin Angus Mackay22-May-06 1:46
Colin Angus Mackay22-May-06 1:46 
QuestionDatagridview from 2 tables Pin
nikitaj22-May-06 1:08
nikitaj22-May-06 1:08 
QuestionC#.net Pin
abhaygalande22-May-06 0:32
abhaygalande22-May-06 0:32 
AnswerRe: C#.net Pin
Robert Rohde22-May-06 0:40
Robert Rohde22-May-06 0:40 
AnswerRe: C#.net Pin
Jax_qqq22-May-06 0:42
Jax_qqq22-May-06 0:42 
AnswerRe: C#.net Pin
Sebastian Schneider22-May-06 1:27
Sebastian Schneider22-May-06 1:27 
AnswerRe: C#.net Pin
Christian Graus22-May-06 1:33
protectorChristian Graus22-May-06 1:33 
QuestionHOWTO make child controls scroll inside a containercontrol Pin
batmike200022-May-06 0:09
batmike200022-May-06 0:09 

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.