上一页 1 2 3 4 5 6 7 8 ··· 20 下一页

2013年11月27日

枚举迭代

摘要: /*枚举迭代如果需要foreach迭代的支持那就要实现接口IEnumerable的GetEnumerator方法返回一个IEnumerable接口的枚举该方法通过MoveNext方法和Current属性来迭代。用yield语句轻松创建枚举器*/using System;using System.Collections.Generic;namespace Frank{ public class Test { public static void Main(string[] args) { /* IL不会把foreach解析为IL语言 C#中定义的fo... 阅读全文

posted @ 2013-11-27 14:25 wp456 阅读(308) 评论(0) 推荐(0)

2013年11月26日

数组段ArraySegment<T>的使用

摘要: /*数组段ArraySegment的使用*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { int[] array1 = new int[]{1,2,3,4,5}; int[] array2 = new int[]{6,7,8,9}; ArraySegment[] as1 = new ArraySegment[]//实例化泛型数组段,指定输入数组的开始索引及个数 { new ArraySegment(arr... 阅读全文

posted @ 2013-11-26 15:23 wp456 阅读(2463) 评论(0) 推荐(0)

数组协变和抗变

摘要: /*数组协变和抗变*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { int[] array = new int[]{1,1}; Get(array);//需要Array类型,传递的是int[]类型 协变 int[] array2 = (int[])Set();//抗变,返回Array类型,需要强制转换为int[]类型 } public static void Get(Array a)//需要Arra... 阅读全文

posted @ 2013-11-26 14:53 wp456 阅读(200) 评论(0) 推荐(0)

Array 抽象类的使用及排序

摘要: /*Array 抽象类在C#中使用[]创建数组其实是Array的表示法,C#会创建一个派生Array的新类,然后就能使用Array的方法和属性了。*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { int[] ar = {1,2};//方括号C#的特殊语法,自动创建了一个派生自Array的类。 System.Console.WriteLine(ar.LongLength+"---"+ar.Rank+"---"+ar.Ge. 阅读全文

posted @ 2013-11-26 14:34 wp456 阅读(285) 评论(0) 推荐(0)

2013年11月25日

数组的定义及遍历方式

摘要: /* 数组的定义及遍历方式*/namespace Frank{ public class Test { public static void Main(string[] args) { #region 一维数组 int[] array0;//声明对象 array0 = new int[4];//定义 array0[0] = 1;//赋值 int[] array1 = new int[4];//声明并定义 array1[0] = 2;//赋值 int[] array2 = new int[1]{1};//声明定义初始化值 int[] array3 = n... 阅读全文

posted @ 2013-11-25 22:21 wp456 阅读(256) 评论(0) 推荐(0)

泛型方法

摘要: /*泛型方法泛型方法不需要定义在泛型类中泛型方法也是可以重载的,如果一个方法有泛型版本和int类型版本,那么能在编译期间确认的版本会优先调用那个类型的版本,然后再选择泛型版本。*/using System;using System.Collections.Generic;namespace Frank{ public class Test { public static void Main(string[] args) { int a = 5; Test t = new Test(); t.Get(a);//调用泛型方法,如果传的类型与定义的不一样... 阅读全文

posted @ 2013-11-25 16:48 wp456 阅读(160) 评论(0) 推荐(0)

泛型结构体

摘要: /*泛型结构体*/namespace Frank{ public class Test { public static void Main(string[] args) { } } public struct Test4 where T:struct //定义泛型结构体,跟普通的结构体没啥区别 { public Test4(T value) { this.T4 = value; } public T T4; }} 阅读全文

posted @ 2013-11-25 16:05 wp456 阅读(416) 评论(0) 推荐(0)

泛型协变和抗变

摘要: /*泛型协变和抗变.net 4.0增加的特性参数是可以协变的方法返回类型是抗变的*/namespace Frank{ public class Test { public static void Main(string[] args) { Rectangle s = new Rectangle(); Rectangle r = new Rectangle(); r.Set(s);//协边,需要基类型,但是可以传递子类型的引用,总是隐士的。 //Rectangle r2 = r.Get();//抗变,需要显示。因为返回的父类型不一定总是子类型中... 阅读全文

posted @ 2013-11-25 16:03 wp456 阅读(225) 评论(0) 推荐(0)

2013年11月22日

泛型类功能

摘要: /*----泛型---性能:泛型类型在JIT时不在进行装箱拆箱类型安全性:定义是什么类型就必须放入什么类型二进制代码重用:可以在.NET中其他语言重用代码的扩展:命名约定:在定义泛型类的时候最好使用T进行类型替代。泛型类功能默认值约束继承静态成员*/using System.Collections;using System.Collections.Generic;namespace Frank{ public class Test { public static void Main(string[] args) { } }}publi... 阅读全文

posted @ 2013-11-22 14:28 wp456 阅读(167) 评论(0) 推荐(0)

泛型---泛型链表

摘要: /*----泛型---性能:泛型类型在JIT时不在进行装箱拆箱类型安全性:定义是什么类型就必须放入什么类型二进制代码重用:可以在.NET中其他语言重用代码的扩展:命名约定:在定义泛型类的时候最好使用T进行类型替代。*/using System.Collections;using System.Collections.Generic;namespace Frank{ public class Test { public static void Main(string[] args) { List li = new List(); LinkedList l... 阅读全文

posted @ 2013-11-22 14:01 wp456 阅读(205) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 ··· 20 下一页

导航