演示PropertyCollection类的使用

来源:互联网 发布:矩阵室内设计 编辑:程序博客网 时间:2024/05/29 18:33

(摘录自《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
 
 

原创粉丝点击