有个 疑问 关于 静态函数
:
public class A
{
...
public static A b
{
A c = new A();
....
}
}有点晕,静态函数名前 类名的出现 不大懂了 静态对象?
给分析分析
:
public class A
{
...
public static A b
{
A c = new A();
....
}
}有点晕,静态函数名前 类名的出现 不大懂了 静态对象?
给分析分析
{
...
public static A b
{
A c = new A();
....
}
}这只是一个自己实例化自己的东西嘛,全局唯一的。
逻辑关系倒腾倒腾就好了,呵呵。
其实不难理解,这个还可以修改一个
public class A
{
public static A _This = null;
public static A This
{
get
{
if (_This == null)
_This = new A();
return _This;
}
} private static string _TestStr = ""; public string TestStr
{
get { return _TestStr; }
set { _TestStr = value; }
} public void ConsoleStr()
{
Console.Write(TestStr);
}
}
class Program
{
static void Main(string[] args)
{
A.This.TestStr = "aaa";
A.This.ConsoleStr();
A a = new A();
a.ConsoleStr();
Console.ReadKey();
}
}
static是一个静态关键字,可以是静态函数,也可以是静态对象
private static string str;
private static vodi Main(){}