(摘录自《C#函数实用手册》冶金工业出版社)
代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataTable testDT = new DataTable("student");
DataColumn testDC = new DataColumn("Id", Type.GetType("System.Int32"));
testDT.Columns.Add(testDC);
testDC = new DataColumn("Name", Type.GetType("System.String"));
testDT.Columns.Add(testDC);
testDC = new DataColumn("School", Type.GetType("System.String"));
testDT.Columns.Add(testDC);
PropertyCollection testPC;
testPC = testDT.ExtendedProperties;
testPC.Add("Id", 1);
testPC.Add("name","ZeLi");
testPC.Add("edu", "Master");
Console.WriteLine("ID :" + testDT.ExtendedProperties["Id"]);
Console.WriteLine("名字:" + testDT.ExtendedProperties["name"]);
Console.WriteLine("学位:" + testDT.ExtendedProperties["edu"]);
Console.ReadLine();
}
}
}
*********************************
结果:
ID :1
名字:ZeLi
学位:Master