Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, let's hit your version with notes, then move on to what you probably wanted. </p> <pre><code>// Here you declare your DoSomething class public class DoSomething { // now you're defining a static function called Main // This function isn't associated with any specific instance // of your class. You can invoke it just from the type, // like: DoSomething.Main(...) public static void Main(System.String[] args) { // Here, you declare some variables that are only in scope // during the Main function, and assign them values System.String apple = args[0]; System.String orange = args[1]; System.String banana = args[2]; System.String peach = args[3]; } // at this point, the fruit variables are all out of scope - they // aren't members of your class, just variables in this function. // There are no variables out here in your class definition // There isn't a constructor for your class, so only the // default public one is available: DoSomething() } </code></pre> <p>Here's what you probably wanted for your class definition:</p> <pre><code>public class DoSomething { // The properties of the class. public string Apple; public string Orange; // A constructor with no parameters public DoSomething() { } // A constructor that takes parameter to set the properties public DoSomething(string apple, string orange) { Apple = apple; Orange = orange; } } </code></pre> <p>And then you could create / manipulate the class like the following. In each case, the instance will end up with Apple = "foo" and Orange = "bar"</p> <pre><code>DoSomething X = new DoSomething("foo", "bar"); DoSomething Y = new DoSomething(); Y.Apple = "foo"; Y.Orange = "bar"; DoSomething Z = new DoSomething() { Apple = "foo", Orange = "bar" }; </code></pre>
 

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