刚刚开始学企业级应用程序开发,今天学习了范型。以下程序实现了几个简单的数据交换:
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);

}
}
}