Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error is exactly as the compiler says. You cannot use <code>var</code> when initializing with a method group. From the <a href="http://msdn.microsoft.com/en-us/library/bb384061.aspx" rel="nofollow">documentation</a>, with my emphasis:</p> <blockquote> <p>var can only be used when a local variable is declared and initialized in the same statement; the variable cannot be initialized to null, or to a <strong>method group</strong> or an anonymous function.</p> </blockquote> <p>In your code, <code>ButtonEquals_Click</code> is a method group.</p> <p>You have to explicitly state the type of the variable if you wish to initialize it with a method group.</p> <p>However, it's fairly obvious that you do not really want to assign a method group to a local variable. Exactly what you are trying to do, I cannot discern from here. </p> <p>It looks to me like you have not quite grasped event driven programming. You need to wait until the user clicks the button, and then respond to that button click in the event handler. The thing to learn about event handlers is that the system calls them, and you do not.</p> <p>So, perhaps what you need to do is move the code inside the if statement into the <code>ButtonEquals_Click</code> event handler. You'll still have plenty of compiler errors when you do that, but it's a step in the right direction.</p> <p>The next step for you, I think, is to try to understand event driven programming a bit more. Start from an empty project and add a couple of buttons. Add click event handlers that do different things. For example, they might call <code>MessageBox.Show</code> with different messages. Then run the program and click on the buttons. Note that the button event handlers only execute when the user clicks the button. Then take a look at your code. Notice how your code does nothing in the <code>ButtonEquals_Click</code> event handler, but is attempting to some how invoke that event from <code>ButtonTimes_Click</code>. Make sure that you fully understand that events are invoked by the framework in response to user input before you proceed.</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.
 

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