是否可以在参数中使用通配符?我有这个代码重复的属性TextLine1,TextLine2,TextLine3和TextLine 4.是否有可能用通配符替换数字,以便我可以根据用户输入传递数字。通配符可用于对象吗?
TextLine1,TextLine2,TextLine3和TextLine 4是ReportHeader类的属性。
public Control returnTextLine(ReportHeader TextLineObj,int i)
{
System.Windows.Forms.Label lblTextLine = new System.Windows.Forms.Label();
lblTextLine.Name = TextLineObj.**TextLine1**.Name;
lblTextLine.Font = TextLineObj.**TextLine1**.Font;
lblTextLine.ForeColor = TextLineObj.**TextLine1**.ForeColor;
lblTextLine.BackColor = TextLineObj.**TextLine1**.BackgroundColor;
lblTextLine.Text = TextLineObj.**TextLine1**.Text;
int x = TextLineObj.**TextLine1**.x;
int y = TextLineObj.**TextLine1**.y;
lblTextLine.Location = new Point(x, y);
return lblTextLine;
}
请帮助...
我在新的关键字得到的错误,并在{TextLine1,TextLine2,TextLine3,TextLine4}说“不包含定义添加” 公共ReadOnlyCollection的TextLine {获得;私人设置; } public ReportHeader() { TextLines = new ReadOnlyCollection {TextLine1,TextLine2}; } –
NewBie
2011-03-31 12:38:20
@NewBie:更新了我的答案。再试一次。 – 2011-03-31 12:41:29