473,386 Members | 1,867 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,386 software developers and data experts.

why use the static function ?

which situation should use the static function ?

--
FireCrow Studio
Kylin Garden
EMail:w0**@sohu.com
ICQ:156134382
Nov 17 '05 #1
4 39194
Static methods enable you to call code without an instance of the class in
which it's defined.

You cannot use instance data in a static method.

A static method should be self-contained. This is to say that it will
perform its function without requiring or saving any stateful data. A
classic static method would be something like...

public static double Multiply(double a, double b)
{
return a*b;
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Kylin" <ga*******@gmail.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
which situation should use the static function ?

--
FireCrow Studio
Kylin Garden
EMail:w0**@sohu.com
ICQ:156134382

Nov 17 '05 #2
Static functions are used in situations where you want to share some
Business Logic code over and over in your UI. Think of them as global
functions. You dont have to create an instance to access the code thus
reducing lot of overhead.

puclic class MyBusinessLogic
{
public static DataTable GetUniqueCustomerList()
{
}
}

In your UI Code you can call-
DataTable myTable=MyBusinessLogic.GetUniqueCustomerList();

--
Jay Balapa
Director Of Software Engineering
www.atginc.com
"Kylin" <ga*******@gmail.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
which situation should use the static function ?

--
FireCrow Studio
Kylin Garden
EMail:w0**@sohu.com
ICQ:156134382

Nov 17 '05 #3
<groan>

If you try really hard you can write a whole application using only static
methods and ensuring the maximum of spaghetti code too.

Static functions should be used only where the architecture demands a clean
and stateless system of operation. The Math class in .NET is a primary
example of good use of static methods.

Using static as a replacement for Global is a recipie for disaster and a
sign of one of two things. #1 having learned programming with classic VB and
#2 having no clue about object oriented architecture.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Jay Balapa" <jb*****@atginc.com> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Static functions are used in situations where you want to share some
Business Logic code over and over in your UI. Think of them as global
functions. You dont have to create an instance to access the code thus
reducing lot of overhead.

puclic class MyBusinessLogic
{
public static DataTable GetUniqueCustomerList()
{
}
}

In your UI Code you can call-
DataTable myTable=MyBusinessLogic.GetUniqueCustomerList();

--
Jay Balapa
Director Of Software Engineering
www.atginc.com
"Kylin" <ga*******@gmail.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
which situation should use the static function ?

--
FireCrow Studio
Kylin Garden
EMail:w0**@sohu.com
ICQ:156134382


Nov 17 '05 #4
> Using static as a replacement for Global is a recipie for disaster and a
sign of one of two things. #1 having learned programming with classic VB
and #2 having no clue about object oriented architecture.
Thanks nothanks for obnoxious remarks.
We have been developing c/c++ enterprise software for quite some time. We
very well understand that static functions are used for utility/helper
functions only.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:u%****************@tk2msftngp13.phx.gbl... <groan>

If you try really hard you can write a whole application using only static
methods and ensuring the maximum of spaghetti code too.

Static functions should be used only where the architecture demands a
clean and stateless system of operation. The Math class in .NET is a
primary example of good use of static methods.

Using static as a replacement for Global is a recipie for disaster and a
sign of one of two things. #1 having learned programming with classic VB
and #2 having no clue about object oriented architecture.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Jay Balapa" <jb*****@atginc.com> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Static functions are used in situations where you want to share some
Business Logic code over and over in your UI. Think of them as global
functions. You dont have to create an instance to access the code thus
reducing lot of overhead.

puclic class MyBusinessLogic
{
public static DataTable GetUniqueCustomerList()
{
}
}

In your UI Code you can call-
DataTable myTable=MyBusinessLogic.GetUniqueCustomerList();

--
Jay Balapa
Director Of Software Engineering
www.atginc.com
"Kylin" <ga*******@gmail.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
which situation should use the static function ?

--
FireCrow Studio
Kylin Garden
EMail:w0**@sohu.com
ICQ:156134382



Nov 17 '05 #5

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

Similar topics

5
by: Marijn | last post by:
I'd like to know how compilers usually handle static variables that are declared inside a function (as opposed to static class-members). Like in: int counter(){ static int c=0; ++c; return c;...
4
by: Howard | last post by:
Hi, I came across some sample code for using a third-party API, and the code in it had several free-standing (i.e., non-member) functions, but strangely, these were declared as 'static'. My...
12
by: dual0 | last post by:
Hello, I found some function like void static foo(...){ .... } what does the static keyword stand for? what is a static function?
5
by: rashmi | last post by:
how to use static function defined in one file in another file is that impposiible in 'c '
6
by: Ravi | last post by:
Hi All: Is there any reason for declaring functions as static in a header file if that header file is going to be included in several other files? The compiler throws a warning for every such...
40
by: vishnu | last post by:
Hi friend, i have a problem in my program what is the use of static function in C lang? plz help me
22
by: Steve - DND | last post by:
We're currently doing some tests to determine the performance of static vs non-static functions, and we're coming up with some odd(in our opinion) results. We used a very simple setup. One class...
1
by: nicolas.gendron | last post by:
Is there a way to do this? I don't want to use sizeof(non_static_member_variable_type) because if the type of my member variable changes, the sizeof operator won't be informe. Any solution? ...
4
by: MichK | last post by:
Hello, I'm new in C#, and I'm working on some application to do direct audio recording and realtime plotting on screen. Now I'm having a lot of trouble to update the screen yet, it has been taking...
4
by: dolphin | last post by:
Hi All I read a .cpp files,find that static void fun(void){......} int main() { .......... } What does this static function mean?Is it the same as the static
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.