Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:27:06+00:00 2026-05-27T15:27:06+00:00

When declaring an event such as public EventHandler<EventArgs> test; I get the title compiler

  • 0

When declaring an event such as

 public EventHandler<EventArgs> test;

I get the title compiler warning.

with the highlight on “test”
event directly above it is declared exact same syntax and works in the same class.

essentially it will not allow me to declare another event, of EventArgs or any other type in this class. If i comment out the declaration and the raise statement, compiles and executes without issue.

And if I ignore the warning and run, on attempting to raise the event such as

test(this,EventArgs.Empty);

get a null reference exception, what gives, I do not understand how an event ever gets assigned to in the first place?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:27:07+00:00Added an answer on May 27, 2026 at 3:27 pm

    Your example doesn’t declare an event, it declares a public field that a delegate can be assigned to.

    The syntax to make that an event is:

    public event EventHandler<EventArgs> test;
    

    Even with that the event will be null if no one ever registers an event handler so you will have to test that test is not null before trying to call it.

    It will be non-null if some other class attached to the event as so:

    instanceOfMyClass.text += AnEventHandlerMethod;
    

    Take a look at the events tutorial on Msdn.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When declaring a code-behind method as private (such as an event handler), the compiler
Are declaring custom .NET event such as this , more common in a winform
Is there any different between declaring event Action<> and event EventHandler<> . Assuming it
I have the following click event. protected void btnUpdate_Click(object sender, EventArgs e) { foreach
The code looks like below: Clock: public class Clock { public event Func<DateTime, bool>
What's the code syntax for declaring a subclass of EventHandler (that you've defined) in
When declaring a template, I am used to having this kind of code: template
Is declaring an attribute of a table as UNIQUE equivalent to declaring it as
When declaring external ant tasks using taskdef, for instance ant-contrib, the proposed setup is
What are differences between declaring a method in a base type virtual and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.