the "x" method needs to be at the same "level" as your Main() and other
methods/properties. There are really only 3 levels to your source file (in
terms of the structure of the class):
namespace mynamespace
{
class myclass
{
public x()
{
}
static Main()
{
}
public string SomePublicProperty="";
}
}
The namespace is the sort of the "top level", then a class is within that,
then EVERYTHING else (which is: methods, properties, enums, structs) are
withing that.
And also yes, static may be giving you a problem too. Normally, a class is
like a blueprint to a house - it's not the house, it's the blueprint to the
house. So, you have to take the blueprints (the class) and build a house
(create an instance/create an object). When you have a static method, that
is part of that class that DOES exist - and exists once for every class. In
other words, imagine this:
namespace mynamespace
{
class myclass
{
public string SomePublicProperty="";
public static string SomeStaticProperty="crap";
}
}
from your code, if you did this:
myclass x = new myclass();
x.SomePublicProperty = "yes";
myclass y = new myclass();
y.SomePublicProperty = "no";
myclass z = new myclass();
z.SomePublicProperty = "maybe";
First of all, A) you have to create an instance of the class in order to
access SomePublicProperty - and B) each "version", or instance of that class
has it's own set of data to if you printed out x.SomePublicProperty,
y.SomePublicProperty and z.SomePublicProperty - you'd see yes, no and
maybe - respectively.
Since a static variable or method exists all the time and the same one
exists for all instances - you don't create an instance of the class, it's
just "there":
myclass.SomeStaticProperty = "stuff";
myclass.SomeStaticProperty = "stuff2";
myclass.SomeStaticProperty = "stuff3";
and if you print out myclass.SomeStaticProperty - it will equal "stuff3",
because there is only one SomeStaticProperty, because it's static.
So to tie this all together, Main() is a static method, and x() is not. So
you need to create an instance of the class you are in, and then use that
instance to call the x() method.
Hope that helps..