using System;
using System.Net.NetworkInformation;
class Person
{
delegate int CacDelegate(int x, int y);
static int Add(int x, int y)
{
return x + y;
}
static int Subtract(int x, int y)
{
return x - y;
}
static int Multiply(int x, int y)
{
return x * y;
}
static int Divide(int x, int y)
{
return x / y;
}
CacDelegate[] methods;
public void Mathmatics()
{
methods = new CacDelegate[] { Add, Subtract, Multiply };
}
public void Caculate(char opcode, int operand1, int operand2)
{
switch (opcode)
{
case '+':
Console.WriteLine("+ :" + this.methods[0](operand1, operand2));
break;
case '-':
Console.WriteLine("- :" + methods[1](operand1, operand2));
break;
case '*':
Console.WriteLine("* :" + methods[2](operand1, operand2));
break;
case '/':
Console.WriteLine("/ :" + methods[3](operand1, operand2));
break;
}
}
}
namespace ConsoleApp1
{
class Program
{
delegate void WorkDelegate(char arg1, int arg2, int arg3);
private static void Main(string[] args)
{
Person person = new Person();
WorkDelegate work = person.Caculate;
work('+', 10, 5);
}
}
}
예제따라 연습중인데 이거 왜 배열이 없다고 오류남? 해결법좀
오류코드정도는 적어줘야 뭘 알지