我正在阅读实现Singleton的教程,代码是
public class Singleton
{
private static readonly Singleton instance = new Singleton();
static Singleton()
{
Console.WriteLine("Static");
}
private Singleton()
{
Console.WriteLine("Private");
}
public static Singleton Instance { get { return instance; } }
public void DoSomething() {
//this must be thread safe
}
}
Run Code Online (Sandbox Code Playgroud)
当我写Singleton.Instance时,输出是
私人
静态
我期待它
静态
私人
原因是当我阅读MSDN教程" https://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx "
我看到在静态构造函数之后调用了公共构造函数.
为什么会有区别?
我有一个字符串
string data = "[City, Delhi]&[State, DL]&[Country, IN]";
Run Code Online (Sandbox Code Playgroud)
从中我想要一本字典.
我认为的方法是
我讨厌这种方法,因为我的字符串已经有"["和"]",我应该可以直接添加到Dictionary.
c# ×2