sharing class code

  • Thread starter Thread starter TJS
  • Start date Start date
T

TJS

I have a class and method (class b method b) that I want to share with all
other classes, so I don't have to keep putting th same code in every class.

How is this done?
 
TJS said:
I have a class and method (class b method b) that I want to share with all
other classes, so I don't have to keep putting th same code in every class.

How is this done?

[cross-posted from
microsoft.public.dotnet.framework.aspnet.buildingcontrols...]

Assuming Class B is in the same namespace as class A, you can make B's
method static.

public class B
{
public static void DoSomething()
{
...
}
}


Then, from class A you could call DoSomething from B using:

B.DoSomething();


Also, see:

Accessing Common Code, Constants, and Functions in an ASP.NET Project
http://aspnet.4guysfromrolla.com/articles/122403-1.aspx

hth


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
Back
Top