using System;
class Program
{
private Action _action = delegate { Console.WriteLine(); };
}
Select 'Console.WriteLine();' and extract method.
using System;
class Program
{
private Action _action = delegate { MyMethod(); }; // error CS0236: A field initializer cannot reference the non-static field, method, or property 'Program.MyMethod()'
private void MyMethod()
{
Console.WriteLine();
}
}
Description
using System;
class Program
{
private Action _action = delegate { Console.WriteLine(); };
}
Select 'Console.WriteLine();' and extract method.
using System;
class Program
{
private Action _action = delegate { MyMethod(); }; // error CS0236: A field initializer cannot reference the non-static field, method, or property 'Program.MyMethod()'
private void MyMethod()
{
Console.WriteLine();
}
}