Сначала давайте добавим в вашу версию заметки, а затем перейдем к тому, что вы, вероятно, хотели.
// 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()
}
Вот что вы, вероятно, хотели для определения класса:
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;
}
}
И тогда вы можете создать / управлять классом, как показано ниже.В каждом случае экземпляр получит Apple = "foo" и Orange = "bar"
DoSomething X = new DoSomething("foo", "bar");
DoSomething Y = new DoSomething();
Y.Apple = "foo";
Y.Orange = "bar";
DoSomething Z = new DoSomething()
{
Apple = "foo",
Orange = "bar"
};