simple namespace question

G

Guest

I have a method that takes a string, formats it and returns it
I want to use this in multiple ASP.NET pages, by putting it in a namespace and using that in each asp.net page

What I don't understand is how to write that namespace so that I can reference that method elsewhere by simply writing
string Message = "Hello world";
string newstring = MyNamespace.MyMethod(Message)

so I can call the method without having to create a new objec

Thankyou, Katie.
 
A

Anatoly

You are talking about static(shared in vb.net) method which allow to execute
method without need in object been created.
example:

class MyClass
{
string static MyMethod(string Input)
{
....
return ...;
}
}

using:
string Message = "...";
string newstring = MyClass.MyMethod(Message);
HTH

Katie S said:
I have a method that takes a string, formats it and returns it.
I want to use this in multiple ASP.NET pages, by putting it in a namespace
and using that in each asp.net page.
What I don't understand is how to write that namespace so that I can
reference that method elsewhere by simply writing :
 
F

francois

Mmhh i am very puzzled by your question as it seems you speak about 2
totally different things.

If you want to import a namespace in your aspx page, at the top just put
something like :

<%@ Import namespace="MyNameSpace" %>

But if you want to do :
"so I can call the method without having to create a new object "
as you say in your message, then the method need to be static (shared in VB)

You will call that method like :
Myclass.MyMethod();

No need to specify the full namespace as you can import it as i showed you.

Best regards,

Francois


Katie S said:
I have a method that takes a string, formats it and returns it.
I want to use this in multiple ASP.NET pages, by putting it in a namespace
and using that in each asp.net page.
What I don't understand is how to write that namespace so that I can
reference that method elsewhere by simply writing :
 
S

Stefano Mostarda

Hi Katie,

Namespaces have no methods, they are only a way to easily identify
classes and avoid collision between classes name. Instead you could
create a class with a static method so, when you want to use it, you
don't have to create an instance of it.

HTH,

Stefano Mostarda MCP
Rome Italy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top