General function

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
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.
 
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
 
Back
Top