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)

导航