单例模式 Singleton Pattern
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SingletonPattern
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form f2 = Singleton.getInstance();
f2.Text = "Form2";
f2.Show();
}
}
public class Singleton
{
private static Form instance = null;
public static
Form getInstance()
{
if(instance == null)
{
instance = new Form();
}
return instance;
}
}
}
希望能帮到你