Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a function within a namespace

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.functionname()".

like image 720
emilios Avatar asked Jun 30 '11 18:06

emilios


1 Answers

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.

like image 165
msarchet Avatar answered Oct 04 '22 14:10

msarchet