C# 如何动态申明变量 和 PROPERTYGRID控件如何动态给属性赋值 (谢谢)
1. private static ReporterGrid reporterGridA1 = new ReporterGrid();
private static ReporterGrid reporterGridA2 = new ReporterGrid();
private static ReporterGrid reporterGridA3 = new ReporterGrid();
private static ReporterGrid reporterGridA4 = new ReporterGrid();
private static ReporterGrid reporterGridA5 = new ReporterGrid();
private static ReporterGrid reporterGridA6 = new ReporterGrid();
private static ReporterGrid reporterGridA7 = new ReporterGrid();
private static ReporterGrid reporterGridA8 = new ReporterGrid();
private static ReporterGrid reporterGridA9 = new ReporterGrid();
private static ReporterGrid reporterGridA10 = new ReporterGrid();
private static ReporterGrid reporterGridA11 = new ReporterGrid();
private static ReporterGrid reporterGridA12 = new ReporterGrid();
private static ReporterGrid reporterGridA13 = new ReporterGrid();
private static ReporterGrid reporterGridA14 = new ReporterGrid();
private static ReporterGrid reporterGridA15 = new ReporterGrid();
private static ReporterGrid reporterGridA16 = new ReporterGrid();
private ReporterGrid[] _Members1 = new ReporterGrid[] { reporterGridA1, reporterGridA2, reporterGridA3, reporterGridA4, reporterGridA5, reporterGridA6, reporterGridA7, reporterGridA8, reporterGridA9, reporterGridA10, reporterGridA11, reporterGridA12, reporterGridA13, reporterGridA14, reporterGridA15, reporterGridA16 };
正如大家所看到的,这个代码实在是太垃圾了.比如有一个ArrayList arrayList = new ArrayList();arrayList有16个元素,如何根据这个arrayList的容量大小来动态申明上面的16个ReporterGrid,并且放入_Members1数组内.
2. [Category("属性配置(主要原料成本表.其他原料成本表.经营业务利润明细表)"), DisplayName("主要原料成本预算表")]
正入大家所看到的,这里的Category, 和 DisplayName属性都是写死的,琢磨了一段时间也不知道怎么把这些弄成变量的形式.请各位专家给予指导
3. [Category("属性配置(主要产品产销表.其他产品产销表.主营业务成本明细表)"), DisplayName("PCP,一、精炼石油产品")]
public ReporterGrid[] Members1
{
get
{
return _Members1;
}
set
{
_Members1 = value;
}
}
[Category("属性配置(主要产品产销表.其他产品产销表.主营业务成本明细表)"), DisplayName("CET,二、化工原料类小计")]
public ReporterGrid[] Members2
{
get
{
return _Members2;
}
set
{
_Members2 = value;
}
}
如上所表示,这是两个PROPERTYGRID的数据集,_Members1的申明为第一个问题上面的申明所表示,_Members2为另一大堆同样的申明,但其实这两个我是可以合并成一个的,如何可以做到呢.谢谢