Last post Jul 31, 2009 10:31 PM by renasis
Jul 31, 2009 07:41 PM|renasis|LINK
I am working with VB.Net and am kinda new. I was wondering, if my asp.net project has a lot of shared functions, can I put them all into one Namespace? Do I have to put them into a class?
Jul 31, 2009 08:11 PM|mbanavige|LINK
You could place them in either a Class or a Module - and yes you could put them all in a single namespace if that's what you want.
Jul 31, 2009 08:31 PM|renasis|LINK
Do I have to place them into a class or module? Could I just put them into a namespace?
Jul 31, 2009 08:37 PM|mbanavige|LINK
You cannot place methods directly into a namespace. They must be in either a class or a module.
Jul 31, 2009 09:21 PM|renasis|LINK
OK. Is there a way where I don't have to write the class each time I call the method? I am planning on placing my shared functions inside a class, which resides in a namespace with the same name. Like so,
Public Class Utility
shared function getsomething()
Then I want to be able to use the getsomething function in another class. Based on an example on the web(http://www.sitecrafting.com/blog/aspnet-20-tips-shared-functions/), it
indicates that I can import the namespace I just created an access the function by its name alone, but I can't seem to get it to work. This is what I am trying to do.
public class x
dim x as string = getsomething 'VS needs Utility. before getsomething
Jul 31, 2009 09:23 PM|Danny117|LINK
Quick simple pseudo code. Have fun without namespaces you can never do implements and really design code that others write for you.
First you need some code in a file seperate from the form or web page in the app_code folder.
Just type namespace at the top of your code I recomend starting with two levels then the class name is the third level.
'then your webpage or form
imports whatever.whatever 'Using whatever.whatever;
'then you can just access the class in your code.
'or write it out
Jul 31, 2009 10:29 PM|mbanavige|LINK
access the function by its name alone
in vb.net, you can place the function in a module instead of a class
Jul 31, 2009 10:31 PM|renasis|LINK
What if I am using the function in another code file in the app_code folder? Does same code apply?