C#实现委托
namespace Delegate
{
delegate void DGSayiHi(string name);//声明委托
delegate void DGDo(string name);
class Program
{
static void Main(string[] args)
{
DGSayiHi sayhi = new DGSayiHi(SayChineseHi);
DGSayiHi sayhi2 = new DGSayiHi(SayEnglishHi);
sayhi += sayhi2;//实际上+=相当于Delegate.Combine, -=相当于Delegate.Remove
sayhi("春晓");
Console.ReadLine();
}
static void SayChineseHi(string name)
{
Console.WriteLine("你好:" + name);
}
static void SayEnglishHi(string name)
{
Console.WriteLine("Hello:" + name);
}
}
}
C#实现的从小到大的冒泡排序:
public void BubbleSort(int[] array)
{
int length = array.Length;
for (int i = 0; i < length - 1; i++)
{
for (int j = length - 1; j > i; j--)
{
// 对两个元素进行交换
if (array[j] < array[j - 1])
{
int temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
}
}
以上所述是小编给大家介绍的C#委托与冒泡排序实例,希望对大家有所帮助。在此也非常感谢大家对易知道(ezd.cc)网站的支持!