473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

General function

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.
Nov 17 '05 #1
2 1058
See the 2 answers you got in the C# NG

Brian W

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:RU********************@twister01.bloor.is.net .cable.rogers.com...
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.

Nov 17 '05 #2
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

"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:RU********************@twister01.bloor.is.net .cable.rogers.com...
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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew MacLean | last post by:
Hello all, I am fairly new to .NET, but not to VB. I have a couple of questions. 1. Shared Code Base I have a solution with several different applications within it. Many of the...
9
by: pankaj_wolfhunter | last post by:
Hi, I need some clearance on the following questions: 1) Does LOAD command updates indexes defined for a table? 2) Is REPLACE option in the LOAD command a logged operation? Help will be...
7
by: Felix Kater | last post by:
Hi, when I need to execute a general clean-up procedure (inside of a function) just before the function returns -- how do I do that when there are several returns spread over the whole function?...
105
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does...
25
by: lovecreatesbeauty | last post by:
Could you talk something about the general rules on the interface (function) design in C program that recognized publically? Or introduce some good advice of yourself. How do you think about...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i donīt need the time data i would like to...
17
by: pamelafluente | last post by:
Hi I have to insert dates into some Access and SQL Databases. I need to be general as the target computer might be in any country. -------- - For access I wrote the follow: Function...
10
by: Dixie | last post by:
I am appending some new fields to a table in vba and when I append a number field with is a byte, it does not inherit any format. I want it to be the General Number format, but it is blank. I...
8
by: Razzbar | last post by:
I've been trying to write a general buffer function that looks something like this: function buffer($arg){ ob_start(); $arg; return ob_get_clean(); } Note that the intention is for this to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.