01 2014 档案
C#4.0泛型的协变,逆变深入剖析
摘要:C#4.0中有一个新特性:协变与逆变。可能很多人在开发过程中不常用到,但是深入的了解他们,肯定是有好处的。 协变和逆变体现在泛型的接口和委托上面,也就是对泛型参数的声明,可以声明为协变,或者逆变。什么?泛型的参数还能声明?对,如果有了参数的声明,则该泛型接口或者委托称为“变体”。List 一群汽车 = new List();List 一群车子 = 一群汽车; 显然,上面那段代码是会报错的, 虽然汽车继承于车子,可以隐士转换为车子,但是List并不继承于List,所以上面的转换,是行不通的。IEnumerable 一群汽车 = new List();IEnumerable 一群... 阅读全文
posted @ 2014-01-21 16:10 jameshappy 阅读(375) 评论(0) 推荐(0)
类型的安全转换
摘要:public class StringUtils { /// /// 获取URL内容 UTF8编码 /// /// URL地址 /// public static string GetContent(string ContentURL) { try { Encoding enc = Encoding.UTF8; //Encoding enc = Encoding.Default; ... 阅读全文
posted @ 2014-01-14 17:33 jameshappy 阅读(1351) 评论(0) 推荐(0)
将查询字符串解析转换为泛型List的名值集合.
摘要:/// ///将查询字符串解析转换为泛型List的名值集合. /// ///查询字符串的值 ///结果 public static List GetMultipleRecords(string records) { List result = new List(); if (string.IsNullOrEmpty(records)) { return result; } ... 阅读全文
posted @ 2014-01-14 17:20 jameshappy 阅读(2147) 评论(0) 推荐(0)
把一个对象转化为xml
摘要:方法一:指定对象private string ToGatheringEMXML(GatheringEMEntity entity) { string retSerialXml = ""; System.IO.MemoryStream StreamRequest = new System.IO.MemoryStream(); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(ty... 阅读全文
posted @ 2014-01-08 17:27 jameshappy 阅读(614) 评论(0) 推荐(0)