Click here to Skip to main content
15,908,768 members
Home / Discussions / C#
   

C#

 
GeneralRe: Confused with the Equals() of Object class Pin
N a v a n e e t h1-Apr-08 20:38
N a v a n e e t h1-Apr-08 20:38 
GeneralRe: Confused with the Equals() of Object class Pin
carbon_golem2-Apr-08 2:48
carbon_golem2-Apr-08 2:48 
GeneralSite Personalization - UserID from the asp_net Profile table Pin
karmasol1-Apr-08 17:46
karmasol1-Apr-08 17:46 
QuestionProblem with Singleton Pattern Pin
Zero Destiny1-Apr-08 17:39
professionalZero Destiny1-Apr-08 17:39 
GeneralRe: Problem with Singleton Pattern Pin
Simon P Stevens1-Apr-08 22:25
Simon P Stevens1-Apr-08 22:25 
GeneralRe: Problem with Singleton Pattern Pin
Rob Philpott1-Apr-08 22:49
Rob Philpott1-Apr-08 22:49 
GeneralRe: Problem with Singleton Pattern Pin
Rob Philpott1-Apr-08 22:51
Rob Philpott1-Apr-08 22:51 
GeneralRe: Problem with Singleton Pattern Pin
carbon_golem2-Apr-08 3:03
carbon_golem2-Apr-08 3:03 
The issue is the static member variable. You should probably declare it private readonly and not static. What you are trying to do with the singleton pattern is force one instance in your application. static classes do that, and if your SomeClass has no internal state, then you should move it to a static class instead. If you insist on keeping the member static, then put the initialization into a static constructor and don't check ==null in the Current property.

public class SomeClass {
    private readonly SomeClass _current;

    public static SomeClass Current {
       get {
           if(_current == null) { _current = new SomeClass();}
           return _current;
       }
    }

    public SomeClass() {
      //Do some stuff
    }
}


public class SomeClass {
    private static SomeClass _current;
    static SomeClass(){
        _current = new SomeClass();
    }

    public static SomeClass Current {
       get {           
           return _current;
       }
    }

    public SomeClass() {
      //Do some stuff
    }
}


Hope that helps.

Scott

"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand

GeneralRe: Problem with Singleton Pattern Pin
Zero Destiny2-Apr-08 4:22
professionalZero Destiny2-Apr-08 4:22 
QuestionHow to pass a parameter in an event Pin
Silvyster1-Apr-08 16:08
Silvyster1-Apr-08 16:08 
GeneralRe: How to pass a parameter in an event Pin
PandemoniumPasha1-Apr-08 17:38
PandemoniumPasha1-Apr-08 17:38 
GeneralRe: How to pass a parameter in an event Pin
Silvyster1-Apr-08 22:12
Silvyster1-Apr-08 22:12 
GeneralRe: How to pass a parameter in an event Pin
J4amieC1-Apr-08 22:30
J4amieC1-Apr-08 22:30 
GeneralInfos, links, best practice etc. for programming a webservice Pin
stephan_0071-Apr-08 12:02
stephan_0071-Apr-08 12:02 
GeneralRe: Infos, links, best practice etc. for programming a webservice Pin
KaptinKrunch1-Apr-08 14:05
KaptinKrunch1-Apr-08 14:05 
GeneralRe: Infos, links, best practice etc. for programming a webservice Pin
Rob Philpott1-Apr-08 22:45
Rob Philpott1-Apr-08 22:45 
Question(XML) Editing a single element within a node Pin
Stupefy1-Apr-08 10:13
Stupefy1-Apr-08 10:13 
GeneralRe: (XML) Editing a single element within a node Pin
damianrda1-Apr-08 10:56
damianrda1-Apr-08 10:56 
GeneralRe: (XML) Editing a single element within a node Pin
Stupefy1-Apr-08 11:03
Stupefy1-Apr-08 11:03 
GeneralRe: (XML) Editing a single element within a node Pin
led mike1-Apr-08 11:04
led mike1-Apr-08 11:04 
GeneralRe: (XML) Editing a single element within a node Pin
led mike1-Apr-08 10:59
led mike1-Apr-08 10:59 
QuestionA style question regarding multi-signature methods Pin
Clive D. Pottinger1-Apr-08 9:19
Clive D. Pottinger1-Apr-08 9:19 
GeneralRe: A style question regarding multi-signature methods Pin
Pete O'Hanlon1-Apr-08 9:28
mvePete O'Hanlon1-Apr-08 9:28 
GeneralRe: A style question regarding multi-signature methods Pin
led mike1-Apr-08 9:43
led mike1-Apr-08 9:43 
GeneralRe: A style question regarding multi-signature methods Pin
Pete O'Hanlon1-Apr-08 22:01
mvePete O'Hanlon1-Apr-08 22:01 

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.