kusanagi
kusanagi

Reputation: 14624

C# access to static inside class

what word can i write to access static function inside class? like self:: in php?

Upvotes: 3

Views: 276

Answers (6)

Independent
Independent

Reputation: 2987

public class Discover 
{
    static int myVariable = 1;

    public Discover()
    {
      var test = myVariable;
    }
 }

Upvotes: 0

Branislav B.
Branislav B.

Reputation: 558

If your static class is named etc. SampleClass, you can access its functions with SampleClass.YourFunction(); . If you want to call a function in other static method, just use the name of the function .

Upvotes: 0

Bogdan Verbenets
Bogdan Verbenets

Reputation: 26952

Write the name of the class. For example:

public static class MyClass { 
public static void HelloWorld(){}
}

And use it like:

MyClass.HelloWorld();

Upvotes: 0

Jon
Jon

Reputation: 437854

There is no such keyword in C#. You need to use the class name, e.g.

MyClass.StaticMember

Upvotes: 2

Lloyd
Lloyd

Reputation: 29668

You just use the type name:

static class Test
{

  public static string GetSomething()
  {
    return "Something";
  }

}

string s = Test.GetSomething();

If you're in the class already you just call the method.

Upvotes: 4

Jaroslav Jandek
Jaroslav Jandek

Reputation: 9563

Simply use StaticMethodName(...) (when inside the class where the static method is defined) or ClassName.StaticMethodName(...).

Upvotes: 2

Related Questions