user710502
user710502

Reputation: 11469

Trying to call static function in a class

I am trying to call a static function from a class but the intellisense is not picking it up?

the function return

 public static ArrayList GetInfo(int infoID)

and i am calling from somewhere else in another class, I was trying to do something like

var myitem = myClassName.GetInfo(x);

but intelisense doesnt pick it up... as I type myClassName.

How can i call it? if at all possible

PS: I cant change the signature of the method :(.

Upvotes: 0

Views: 122

Answers (3)

balexandre
balexandre

Reputation: 75123

normally you do have a namespace as well, plus that static method has to be inside it's own class, for example, something like:

namespace MyHelpers {

    public static class ArrayHelpers {

        public static ArrayList GetInfo(int infoID) { ... }
    }
}

now, no matter where you are in your application, and if that library is referenced to your current project you simply call it

ArrayList myitem = MyHelpers.ArrayHelpers.GetInfo(x);

remember that you need to give the full path and if your namespace is called namespace Model.Helpers { ...

then the full path will be:

ArrayList myitem = Model.Helpers.ArrayHelpers.GetInfo(x);

is you are using the using declaration

using Model.Helpers;

you can use

ArrayList myitem = ArrayHelpers.GetInfo(x);

Upvotes: 1

madC
madC

Reputation: 243

Did you create the class in a subfolder of your project? If so, you need to call it like this:

subfolder.myclassname.getinfo()

Upvotes: 1

user925777
user925777

Reputation:

Static functions cant be accessed with variable name, but with class name. So basicly just call either just GetInfo(int) ( if you want to call it within the class where the GetInfo() is ) or YourClass.GetInfo(int) ( outside the class where GetInfo() is ).

If you are calling outside the class, make sure that you are using same namespace in both, or you are using appropriate using statements.

Upvotes: 1

Related Questions