public class Cycle
{
public int id { get; set; }
public string name { get; set; }
}
List<Cycle> collection = new List<Cycle>
{
new Cycle {id=0,name="按年发放"},
new Cycle {id=1,name="按半年发放"},
new Cycle {id=2,name="按季度发放"},
new Cycle {id=3,name="按月发放"},
new Cycle {id=4,name="不定期发放"},
};
这样显得很菜鸟吧。有什么办法可以不用在每个窗体中这样写一遍这个东西呀
我把它写在一个单独的类中,好像不行
关键是有数据,这些数据也没有必要保存在数据中 ------解决方案-------------------- x
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<Cycle> cycleList = StaticList.collection;
foreach (Cycle c in cycleList)
{
Console.WriteLine(c.id + " " + c.name);
}
}
}
public class Cycle
{
public int id { get; set; }
public string name { get; set; }
}
public class StaticList
{
public static List<Cycle> collection = new List<Cycle>
{
new Cycle {id=0,name="按年发放"},
new Cycle {id=1,name="按半年发放"},
new Cycle {id=2,name="按季度发放"},
new Cycle {id=3,name="按月发放"},
new Cycle {id=4,name="不定期发放"},
};
}
}