static event generates CS0052

G

Guest

What is the right way to declare a static event handler?

I have a:

delegate void TestEvent(string ID, ref string payload);

namespace TestNS
{
public class TestFrm : System.Windows.Forms.Form
{
public static event TestEvent newEvent;
....

And this last line gives me compiler error CS0052: "Inconsistent
accessibility...."

I am trying to setup this class so I can add event handlers from other
(external) classes without reference to an instance of TestFrm.

Unfortunately, the MSDN explanation and additonal help at
http://msdn.microsoft.com/library/d...ml/vclrfRemarksOnUsingAccessibilityLevels.asp were not at all illuminating....
 
B

Bruce Wood

You need to say

public delegate void TestEvent(string ID, ref string payload);

at the moment your delegate is "internal", which is inconsistent with
the declaration of the "public" event in TestFrm.
 
L

Linda Liu [MSFT]

Hi,

Thank you for posting.
You should state delegate TestEvent as public just as the following.
public delegate void TestEvent(string ID,ref string payload);
That will be ok.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top