Please I am facing a problem while accessing a function within a class inside a namespace in C#.
The format that i know is as follows: namespace.classname.functionname();
However, the above method is reporting for me the following error:
An object reference is required for the non-static field, method or property "namespace.classname.functionnam开发者_如何学Ce()".
You need to declare an instance of the Class that contains the function
namespace.classname YourClass = new namespace.classname();
then you can use the function as follows
YourClass.functionname();
If you want to be able to use the function without declaring an instance of the class it needs to be a static funciton.
You need to create an instance of your object first if it's not a static method - your code will end up looking like this:
namespace.classname VARIABLENAME = new namespace.classname(CONSTRUCTOR ARGUMENTS) VARIABLENANME.functionname()
精彩评论