Click here to Skip to main content
15,888,733 members
Home / Discussions / C#
   

C#

 
GeneralRe: ListView with sub-lists Pin
Heath Stewart28-Apr-04 6:20
protectorHeath Stewart28-Apr-04 6:20 
GeneralRe: ListView with sub-lists Pin
Heath Stewart28-Apr-04 6:23
protectorHeath Stewart28-Apr-04 6:23 
GeneralRe: ListView with sub-lists Pin
Jon G28-Apr-04 6:31
Jon G28-Apr-04 6:31 
GeneralDetermining app close by User or Windows Pin
ABean28-Apr-04 4:03
ABean28-Apr-04 4:03 
GeneralRe: Determining app close by User or Windows Pin
Heath Stewart28-Apr-04 4:14
protectorHeath Stewart28-Apr-04 4:14 
GeneralStatic to Instance Pin
sreejith ss nair28-Apr-04 3:53
sreejith ss nair28-Apr-04 3:53 
GeneralRe: Static to Instance Pin
Colin Angus Mackay28-Apr-04 4:02
Colin Angus Mackay28-Apr-04 4:02 
GeneralRe: Static to Instance Pin
Heath Stewart28-Apr-04 4:09
protectorHeath Stewart28-Apr-04 4:09 
What? Can you try explaining a little better?

To access a static member, first make sure the access modifier allows it. It should be public for all code to access it, protected for derivative classes to access it, internal for code in the same assembly to access it, and protected internal for code in the same assembly or derivative code in any assembly to access it. If you're not specifying an access modifier, than members default to private.

Then, just access the member using the Type - not the instance:
MyClass.MyStaticMethod();
If you're calling a static method or getting/setting a static field or property in defined on the same class in which your code is currently executing, you don't have to specify the class name, though I personally find it easier to read.

If you're trying to access instance data through a static member (bad idea), then your instance must get/set itself as a static member like so:
public class MyClass
{
  private static object syncRoot = new object();
  public MyClass()
  {
    if (theInstance == null)
      lock (syncRoot)
        if (theInstance == null)
          theInstance = this;
  }
  private static MyClass theInstance;
  public static MyClass TheInstance
  {
    get { return theInstance; }
  }
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Static to Instance Pin
Jeff Varszegi28-Apr-04 4:37
professionalJeff Varszegi28-Apr-04 4:37 
GeneralRe: Static to Instance Pin
Dave Kreskowiak28-Apr-04 4:17
mveDave Kreskowiak28-Apr-04 4:17 
GeneralRe: Static to Instance Pin
Jeff Varszegi28-Apr-04 4:35
professionalJeff Varszegi28-Apr-04 4:35 
Generallist as parameter (C++/C# interoperability) Pin
sharonz28-Apr-04 2:25
sharonz28-Apr-04 2:25 
GeneralRe: list as parameter (C++/C# interoperability) Pin
Heath Stewart28-Apr-04 3:56
protectorHeath Stewart28-Apr-04 3:56 
GeneralRe: list as parameter (C++/C# interoperability) Pin
sharonz28-Apr-04 4:22
sharonz28-Apr-04 4:22 
GeneralRe: list as parameter (C++/C# interoperability) Pin
Roman Rodov28-Apr-04 15:37
Roman Rodov28-Apr-04 15:37 
GeneralRe: list as parameter (C++/C# interoperability) Pin
sharonz28-Apr-04 20:57
sharonz28-Apr-04 20:57 
QuestionUnique integer from string? Pin
Nathan Ridley28-Apr-04 2:20
Nathan Ridley28-Apr-04 2:20 
AnswerRe: Unique integer from string? Pin
amatyasik28-Apr-04 3:46
amatyasik28-Apr-04 3:46 
AnswerRe: Unique integer from string? Pin
Heath Stewart28-Apr-04 3:53
protectorHeath Stewart28-Apr-04 3:53 
AnswerRe: Unique integer from string? Pin
Jeff Varszegi28-Apr-04 4:49
professionalJeff Varszegi28-Apr-04 4:49 
GeneralRe: Unique integer from string? Pin
Nathan Ridley28-Apr-04 17:57
Nathan Ridley28-Apr-04 17:57 
GeneralRe: Unique integer from string? Pin
Jeff Varszegi29-Apr-04 2:55
professionalJeff Varszegi29-Apr-04 2:55 
GeneralDataview Pin
Appelz28-Apr-04 1:28
Appelz28-Apr-04 1:28 
GeneralRe: Dataview Pin
Mazdak28-Apr-04 1:43
Mazdak28-Apr-04 1:43 
GeneralRe: Dataview Pin
Appelz28-Apr-04 20:27
Appelz28-Apr-04 20:27 

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.