Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a big difference between <i>fields</i> and <i>events</i>. There's an excellent article <a href="http://blog.monstuff.com/archives/000040.html" rel="nofollow">here</a> outlining the differences, but that's the answer to your question: A field can be assigned a value; an event looks like a field but is a very different beast.</p> <p><strong>Edit</strong></p> <p>From the article I linked to:</p> <blockquote> <p>We have seen that the event keyword is a modifier for a delegate declaration that allows it to be included in an interface, constrains its invocation from within the class that declares it, <b>provides it with a pair of customizable accessors (add and remove)</b>, and forces the signature of the delegate </p> </blockquote> <p>Remember that <code>event</code> is a shortcut; behind the scenes, the compiler creates an object with <code>add()</code> and <code>remove()</code> methods. Like:</p> <pre><code>public class Button { public event EventHandler Click { void add {...} void remove {...} } } </code></pre> <p>Perhaps this will offer some insight... :</p> <pre><code>Button btn = new Button {Click += (s, e) =&gt; MessageBox.Show("hello")}; </code></pre> <p>The error message you get is "Cannot initialize type 'Button' with a collection initializer because it does not implement IEnumerable"</p> <p><br /> Still another note... if you assign the event handler from within the form, you can do this:</p> <pre><code>this.button1.Click += (s, e) =&gt; this.textBox1.Text = e.ToString(); </code></pre> <p>You couldn't access form variables from the code you've created. I get where you're coming from, and I don't disagree... what you're doing <i>could</i> be made to work. I guess my point is that there are reasons why the decision was made <i>not</i> to make it work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload