2011-11-8
来源:互联网 发布:73小时高跟鞋官网淘宝 编辑:程序博客网 时间:2024/05/01 13:53
今天讲了泛类型
就是这个类型代表任何的类型,呵呵,挺奇妙
下面附上我上课时跟着写的代码吧
这是一个类:
public class Point<T> //泛类型
{
private T xPos;
private T yPos;
public T X
{
get { return this.xPos; }
set { this.xPos = value; }
}
public T Y
{
get { return this.yPos; }
set { this.yPos = value; }
}
public override string ToString()
{
return string.Format("X:{0}Y:{1}",xPos,yPos);
}
public Point(T x,T y)
{
xPos = x;
yPos = y;
}
}
这是一个方法
protected void Page_Load(object sender, EventArgs e)
{
int a = 10;
int b = 20;
//Swap(ref a,ref b);
this.Swap(ref a, ref b);
Response.Write(string.Format("a:{0};b:{1}", a, b));
}
public void Swap(ref int a, ref int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
public void Swap(ref float a, ref float b)
{
float temp;
temp = a;
a = b;
b = temp;
}
public void Swap<T>(ref T a, ref T b) //泛型方法
{
T temp;
temp = a;
a = b;
b = temp;
}
- 2011-8-11
- 2011-11-8
- 2011-8-1 11:10:12
- 2011-8-4 21:37:11
- 2011-8-6 11:23:10
- 2011-8-9 11:58:53
- 2011-8-11 10:40:54
- 2011-8-11 10:16:54
- 2011-8-11 10:47:58
- 2011-8-11 10:53:13
- 2011-8-11 13:03:14
- 2011-8-11 14:24:44
- 2011-8-11 19:50:53
- 2011-8-12 11:18:04
- Linkedin 面试题 8/11/2011
- android开发技术文章荟萃【2011-11-8】
- 2011年8月16日19:42:11
- 2011-11-8 自定义标签和简单标签
- 系统的了解存储过程
- BodyTagSupport
- fork 后子进程copy父进程的什么资源
- 提交form的时 把另外一个form里面的条件带入提交
- C#参数传递方式及使用情境
- 2011-11-8
- 配置虚似主机
- 基于html5的更好的web form
- 新闻系统分析
- 标准模板库(STL)学习探究之Double Ended Queue容器
- C++中数值的后缀
- JSP自定义标签-日期格式化
- HTML介绍与应用
- window.h