【发布时间】:2014-03-13 14:24:22
【问题描述】:
我无法为我的问题找到正确的标题,因为我的问题有点奇怪。先解释一下我的代码
public class Route
{
public String Id {get;set;}
public string routeNo {get;set;}
public string source {get;set;}
}
数据交换类。我有包含路线类所有字段的获胜表格。对于每个变量,我都有label, TextBox, ErrorLabel。我有在休假时调用的函数。
public partial class AddRoute : Form
{
Route r=null;
public AddRoute()
{
InitializeComponent();
r = new Route();
}
private void textBoxSource_Leave(object sender, EventArgs e)
{
showErrorLabel(labelSourceError, textBoxSource.Text, r.source);
}
}
在表单构造函数中初始化的 Route 类的对象 r。
private void showErrorLabelString(Label l, string textboxtext, Route.source a)
{
if ((string.IsNullOrEmpty(s)) || (s.Length > 50))
{
isError = isError && false;
l.Text = "Please Enter Data and Should be smaller than 50 Character";
l.Visible = true;
}
else
{
a = textboxtext;
}
}
现在是解释问题的时候了。我想要所有文本框离开事件的通用函数showErrorLabelString(Label l, string textboxtext, Route.source a),它将检查数据是否正确,如果是,则将其分配给类变量。但问题是showErrorLabelString() 中的data type 应该是什么来动态识别我需要在哪个类的变量中赋值。现在你一定要想想你为什么会这样,理由
- 提高性能
- 所有数据在离开事件时都经过验证,并分配到类对象中,这将节省少量
if else condition以检查数据是否经过验证。 - 减少按钮点击事件的负载。
- 最后是尝试不同的东西。
【问题讨论】:
标签: c# .net winforms function class