Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
| public class Singleton { private static readonly Singleton _instance = new Singleton(); private Singleton() { } public static Singleton GetInstance() { return _instance; } } |
| public class Singleton { private static Singleton _instance; private Singleton() { } public static Singleton GetInstance() { if (_instance == null) _instance = new Singleton(); return _instance ; } } |
| private void button1_Click(object sender, EventArgs e) { Singleton.GetInstance().Message = "mon message"; MessageBox.Show(Singleton.GetInstance().Message); Form2 oForm2 = new Form2(); oForm2.ShowDialog(); } |
| private void button1_Click(object sender, EventArgs e) { MessageBox.Show(Singleton.GetInstance().Message); } |
| public class Singleton { private static readonly Singleton _instance = new Singleton(); public string Message; private Singleton() { } public static Singleton GetInstance() { return _instance; } } |