using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Master
{
int physical;
public Master(int physical)
{
this.Physical = physical;
}
public int Physical { get => physical; set => physical = value; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
delegate void AutoTask(Master m);
class Program
{
static void Main(string[] args)
{
Master m = new Master(5);
AutoTask at = Task01;
at += Task02;
at += Task03;
at(m);
}
public static void Task01(Master m)
{
if (m.Physical >= 5)
{
m.Physical -= 5;
}
else
{
return;
}
Console.WriteLine("任务一开启!");
Console.WriteLine("任务一完成!");
}
public static void Task02(Master m)
{
if (m.Physical >= 5)
{
m.Physical -= 5;
}
else
{
return;
}
Console.WriteLine("任务二开启!");
Console.WriteLine("任务二完成!");
}
public static void Task03(Master m)
{
if (m.Physical >= 5)
{
m.Physical -= 5;
}
else
{
return;
}
Console.WriteLine("任务三开启!");
Console.WriteLine("任务三完成!");
}
}
传入一个参数m为共用。