c# 输入 输出

来源:百度知道 编辑:UC知道 时间:2024/05/23 00:18:34
public aa(string a)
{...
return datatable
}
如何写函数,输入a;返回一个datatable;
调用的时候
datatable tab1=new datatable
tab1=aa(1);
如何实现?不知道函数怎么写,怎么调?

public DataTable ToDataTable(string a)
{
DataTable dt = new DataTable(a);
return dt;
}

DataTable tab1 = ToDataTable("dff");
//得到一个表,表名 Name = “dff”

就是定义一个用来查询表的方法吧
private datatable aa(string a)
{
..
return dt;
}
在同一个类里的话 调用 dt =aa("1");就行了
在同一命名空间下的话
方法定义为 public static datatble aa(string a)
{
..
return dt;
}
静态的方法 放在类里
类.aa("1") 直接用就行了

你不光要new DataTable
还要new DataRow和DataColumn

DataTable GetDataTable(string a){
switch(a){
case "a":
//return table a;
case "b":
//return table b;
}
}
要的是这个效果?
T GetTableService<T>(string a){
if(Type.GetType(a) is T){
//return data table a;
}
else if(...)
// return something other here.
}
还是这样?