C#范型实例运用1
发布:志豪 | 发布时间: 2008年10月16日刚刚开始学企业级应用程序开发,今天学习了范型。以下程序实现了几个简单的数据交换:
using System;
using System.Collections.Generic;
using System.Text;
namespace jiaohuan
{
public class jiaohuan
{
T temp = default(T);
//交换数据
public void prinf(T[] list, int i, int j)
{
this.temp = list[i];
list[i] = list[j];
list[j] = temp;
}
//输出数据
public void printf(T[] list)
{
foreach (T infor in list)
{
Console.WriteLine(infor);
}
Console.WriteLine();
}
}
class Program
{
static void Main(string[] args)
{
jiaohuan jh = new jiaohuan();
int[] a = new int[10];
for (int i = 0; i < a.Length; i++)
{
a[i] = i + 1;
}
Console.WriteLine("-----交换前------");
jh.printf(a);
Console.WriteLine("-----交换后------");
jh.prinf(a,9,0);
jh.printf(a);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace jiaohuan
{
public class jiaohuan
{
T temp = default(T);
//交换数据
public void prinf(T[] list, int i, int j)
{
this.temp = list[i];
list[i] = list[j];
list[j] = temp;
}
//输出数据
public void printf(T[] list)
{
foreach (T infor in list)
{
Console.WriteLine(infor);
}
Console.WriteLine();
}
}
class Program
{
static void Main(string[] args)
{
jiaohuan
int[] a = new int[10];
for (int i = 0; i < a.Length; i++)
{
a[i] = i + 1;
}
Console.WriteLine("-----交换前------");
jh.printf(a);
Console.WriteLine("-----交换后------");
jh.prinf(a,9,0);
jh.printf(a);
}
}
}
发布:志豪 | 分类:asp.net | 评论:0 | 引用:0 | 浏览:
| TrackBack引用地址
- 相关文章:
C#范型实例运用1 (2008-10-16 23:59:54)







