C# 的泛型以及网络下载Xml文件和读取Xml文件

来源:互联网 发布:电信网络连接错误691 编辑:程序博客网 时间:2024/06/06 00:49

 一 、泛型

      1) 通过泛型可以定义类型安全的数据类型,他的最显著的应用就是创建集合类,可以约束集合类内部的元素类型

 

 二 、定义泛型

      1)List 泛型  : List<Student>  students = new  List<Student>();    集合泛型

      2)Dictionary泛型 : Dictionary<string ,Student>  students = new Dictionary<string , Student>();   键值集合

 

三  、里氏替换原则

     1) is 和 as 操作符的使用

                is :判断 对象的类型是否相同

                as :将对象的类型进行强制转换

 

四 、 网络下载 和  读取  XML 文件

      1)    using System.Net;

                WebClient myClien = new WebClient();

                myClient.DownLoadFile("下载地址", "文件保存名");

       2)   using System.Xml;

                XmlDocument myXml = new  XmlDocument();

                myXml.Load("文件保存名");

 

            

原创粉丝点击