what word can i write to access static 开发者_运维技巧function inside class? like self:: in php?
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.
Simply use StaticMethodName(...)
(when inside the class where the static method is defined) or ClassName.StaticMethodName(...)
.
There is no such keyword in C#. You need to use the class name, e.g.
MyClass.StaticMember
Write the name of the class. For example:
public static class MyClass {
public static void HelloWorld(){}
}
And use it like:
MyClass.HelloWorld();
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 .
public class Discover
{
static int myVariable = 1;
public Discover()
{
var test = myVariable;
}
}
精彩评论