把代码过程中比较好的一些代码段做个记录,如下的代码是关于C#中委托用法演示的代码,应该能对各朋友有一些帮助。
using System;
using System.Collections.Generic;
using System.Text;
namespace AnonymousDelegate_Sample
{
delegate decimal CalculateBonus(decimal sales);
class Employee
{
public string name;
public decimal sales;
public decimal bonus;
public CalculateBonus calculation_algorithm;
}
class Program
{
static decimal CalculateStandardBonus(decimal sales)
{
return sales / 10;
}
static void Main(string[] args)
{
decimal multiplier = 2;
CalculateBonus standard_bonus = new CalculateBonus(CalculateStandardBonus);
Employee[] staff = new Employee[5];
for (int i = 0; i < 5; i++)
staff[i] = new Employee();
staff[0].name = "Mr Apple";
staff[0].sales = 100;
staff[0].calculation_algorithm = standard_bonus;