Iam very new to C#. I am learning more about delegates. When I run this code, I get the following error:
A field initializer cannot reference the nonstatic field at the line:
CalArepointer cpointer = CalculateArea;
Here is my program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace calculatearea
{
class Program
{
delegate double CalArepointer(int r);
CalArepointer cpointer = CalculateArea;
static void Main(string[] args)
{
double area = cpointer.Invoke(20);
Console.ReadKey();
}
double CalculateArea(int r)
{
return 3.14 * r * r;
}
}
}