DataTable workTable = new DataTable("Customers");
DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32));
workCol.AllowDBNull = false;
workCol.Unique = true;
workTable.Columns.Add("CustLName", typeof(String));
workTable.Columns.Add("CustFName", typeof(String));
workTable.Columns.Add("Purchases", typeof(Double));typeof(Double))这句什么意思,看了一下msdn对typeof的解释还是不明白
msdn:
type
要获得其 System.Type 对象的类型。
备注
不能重载 typeof 运算符。若要获得一个表达式的运行时类型,可以使用 .NET Framework 方法 GetType
不明白明明说了是string怎么还要typeof(String);
DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32));
workCol.AllowDBNull = false;
workCol.Unique = true;
workTable.Columns.Add("CustLName", typeof(String));
workTable.Columns.Add("CustFName", typeof(String));
workTable.Columns.Add("Purchases", typeof(Double));typeof(Double))这句什么意思,看了一下msdn对typeof的解释还是不明白
msdn:
type
要获得其 System.Type 对象的类型。
备注
不能重载 typeof 运算符。若要获得一个表达式的运行时类型,可以使用 .NET Framework 方法 GetType
不明白明明说了是string怎么还要typeof(String);
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn();
dc1.ColumnName = "a";
dt.Columns.Add(dc1);
workTable.Columns.Add("CustFName", typeof(String));
workTable.Columns.Add("Purchases", typeof(Double));typeof(String)返回一个System.String
typeof(Double)返回一个返回一个System.Doubletypeof不需要创建实例,比 GetType效率要高