Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# implementing interface with events [closed]

Tags:

c#

interface

I have and interface as shown below:

public delegate void ScriptFinished();

public interface IScript
{
    event ScriptFinished ScriptFinishedEvent;
}

Now I want to implement the interface as shown below:

public class Script : IScript
{
    event ScriptFinished ScriptFinishedEvent;
}

But I get error:

'Script.ScriptFinishedEvent' cannot implement an interface member because it is not public.

Ok, I add public to the event:

public interface IScript
{
    public event ScriptFinished ScriptFinishedEvent;
}

But the error is:

The modifier 'public' is not valid for this item

What I do wrong here and how can I implement an interface with events?

like image 442
folibis Avatar asked Sep 19 '25 09:09

folibis


1 Answers

Change:

public class Script : IScript
{
    event ScriptFinished ScriptFinishedEvent;
}

to:

public class Script : IScript
{
    public event ScriptFinished ScriptFinishedEvent;
}

'Script.ScriptFinishedEvent' cannot implement an interface member because it is not public.

is referring to the class, not the interface.

like image 167
mjwills Avatar answered Sep 21 '25 01:09

mjwills