日期:2014-05-20 浏览次数:20829 次
public partial class Form3 : Form { MyClass myClass = new MyClass(); public Form3() { InitializeComponent(); } private void Form3_Activated(object sender, EventArgs e) { myClass.Add("汽车"); myClass.Add("客车"); this.comboBox1.Items.AddRange(myClass.MyType.ToArray()); } } public class MyClass { private List<string> myType; public MyClass() { myType = new List<string>(); } public List<string> MyType { get { return this.myType; } set { this.myType = value; } } public void Add(string name) { if (!myType.Contains(name)) { myType.Add(name); } } public void Remove(string name) { if (myType.Contains(name)) { myType.Remove(name); } } }