How to access a function in a namespace

I am having a problem accessing a function inside a class inside a namespace in C #.

The format that I know is as follows: namespace.classname.functionname();

However, the above method tells me the following error:

An object reference is required for a non-static field, method, or property "namespace.classname.functionname ()".

+5
source share
2 answers

You need to declare an instance of the class containing the function

namespace.classname YourClass = new namespace.classname();

then you can use the function as follows

YourClass.functionname();

If you want to use a function without declaring an instance of the class, it must be a static function.

+8
source

, - :

namespace.classname VARIABLENAME = . (ARGUMENTS CONSTRUCTOR) VARIABLENANME.functionname()

+1

All Articles