General function

M

Maziar Aflatoun

Hi,

Is there way in C# (or C#.net) to just define a function without having to
initialize the class every time. For instance a function that takes a
number, adds 2 and multiplies by 10. I know how to do it in a class. But
the problem with classes is that it has to be instantiated every time.

So for example in my code I want to be able to just call
xx = myfunctionname(2);

Thank you
Maziar A.
 
A

AlexS

Use static methods.
E.g.

class SomeClass {
public static MyResultType MyFunc(...) {
....
}
}

It could be called from anywehere in assembly subject to visibility rules as

MyResultType result=SomeClass.MyFunc(...);

No need to instantiate SomeClass.

Check static modifier and related articles in MSDN

HTH
Alex
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top