例如:
DataTable table = new DataTable()
{
Columns = new DataColumnCollection(
{
new DataColumn("col1"),
new DataColumn("col2")
})
});
你说的是集合初始化器 http://msdn.microsoft.com/en-us/library/bb384062.aspxC# 3 中添加的功能。它是这样完成的:
DataTable table = new DataTable()
{
Columns =
{
new DataColumn("col1"),
new DataColumn("col2")
}
};
这不会调用集合构造函数,它使用 DataTable 中已存在的集合。
这是 Columns.Add() 的简写,因此不需要 Columns 有 setter。
您与问题中的代码非常接近!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)