newbie namespace question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'd like to place a method in a namespace which I can easily call from any of my asp.net pages.
The method formats a string, and I'd like to just call it with a string without instantiating a new object ie:

string Message = "hello world";
Message = MyNameSpace.MyMethod( Message );

How can I do this? Thanks - Katie.
 
You cannot. All methods HAVE TO be placed within a class. So what you do
is create a class somewhere and call something like
MyNamespace.MyClass.MyMethod(...).


Katie said:
Hi,

I'd like to place a method in a namespace which I can easily call from any of my asp.net pages.
The method formats a string, and I'd like to just call it with a string
without instantiating a new object ie:
 
You cannot. All methods HAVE TO be placed within a class. So what you do
I am sorry you got such an answer, but maybe I am just not clear about your
question...
as far as I understand it, of course you can, what you want is 2 things:
A) make a static/shared function if it is part of a class. this allows you
to avoid needing to make an instance of a class:
public class ACls
public shared function A()as integer
return 444
end function
end class

to call simply write
dim myint as integer = ACls.A()

another option, allows you to not even have a class, that is called a
module:
public Module AMdl
public function x() as integer
return 444
end function
end Module

this is the same, except that all function in a module are static/shared so
you can not (need not) use the shared keyword.

I hope this answers your need.
Heranan.
 
csmba said:
I am sorry you got such an answer, but maybe I am just not clear about your
question...
as far as I understand it, of course you can, what you want is 2 things:
A) make a static/shared function if it is part of a class.

That is still part of a class, however, not directly part of the
namespace as the OP originally asked for.

Methods do not belong to namespaces - Peter is correct.
 
Back
Top