The case you cite this is a valid use of the static method. System.Math is a
prime example of this. Each method is self contained, works on the
parameters supplied and returns some value. System.Math cannot be
instantiated and encapsulates no data.
Take a look at the method prototypes for Math or perhaps peek inside with
Reflector.
Be careful when designing your architecture that you don't begin using the
static system as a substitute for global methods and variables. This is very
bad pracatice.

Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
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.
>> You seem to have confused the intent of the public versus private
>> accessor and the static keyword.
[quoted text clipped - 44 lines]
>
> Thanks again.
> Thank you all for the replies - I really appreciate it. I have a C++
> background and am preparing for an interview.
>
> Suppose I am writing a general utility 'class' (simple functions like
> Max, Min, Average, etc) that does not need access to instance members
> because each function is self contained.
Right. In that case, not only could all the methods be static, but you
might want to mark the whole *class* as being static. That would
prevent it being instantiated in the first place.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Schizoid Man - 02 Mar 2008 19:15 GMT
>> Thank you all for the replies - I really appreciate it. I have a C++
>> background and am preparing for an interview.
[quoted text clipped - 6 lines]
> might want to mark the whole *class* as being static. That would
> prevent it being instantiated in the first place.
Thank you for the answers.
Schizoid Man - 03 Mar 2008 16:26 GMT
>> Thank you all for the replies - I really appreciate it. I have a C++
>> background and am preparing for an interview.
[quoted text clipped - 6 lines]
> might want to mark the whole *class* as being static. That would
> prevent it being instantiated in the first place.
Hi Jon, Bob,
Just to continue this thread for a moment...
Suppose I'm writing a class for a statistical distribution. I write the
appropriate constructors, properties and methods (in this case a simple
mean, or average). In this case I would just use the declaration 'public
double', and its usage would be:
StatDist test = new StatDist();
double Avg = test.Average();
However, if I want to also write a general purpose Average function in
the same class, I'd want to overload the function using 'public static
double' so that its usage would be:
double x[] = { ... };
double Avg = StatDist.Average(x);
Is it a good (or bad) idea to overload the function and make one of them
static all in the same class?
Regards,
Schiz
Schizoid Man - 03 Mar 2008 16:26 GMT
>> Thank you all for the replies - I really appreciate it. I have a C++
>> background and am preparing for an interview.
[quoted text clipped - 6 lines]
> might want to mark the whole *class* as being static. That would
> prevent it being instantiated in the first place.
Hi Jon, Bob,
Just to continue this thread for a moment...
Suppose I'm writing a class for a statistical distribution. I write the
appropriate constructors, properties and methods (in this case a simple
mean, or average). In this case I would just use the declaration 'public
double', and its usage would be:
StatDist test = new StatDist();
double Avg = test.Average();
However, if I want to also write a general purpose Average function in
the same class, I'd want to overload the function using 'public static
double' so that its usage would be:
double x[] = { ... };
double Avg = StatDist.Average(x);
Is it a good (or bad) idea to overload the function and make one of them
static all in the same class?
Regards,
Schiz
Schizoid Man - 03 Mar 2008 16:28 GMT
>> Thank you all for the replies - I really appreciate it. I have a C++
>> background and am preparing for an interview.
[quoted text clipped - 6 lines]
> might want to mark the whole *class* as being static. That would
> prevent it being instantiated in the first place.
Hi Jon, Bob,
Just to continue this thread for a moment...
Suppose I'm writing a class for a statistical distribution. I write the
appropriate constructors, properties and methods (in this case a simple
mean, or average). In this case I would just use the declaration 'public
double', and its usage would be:
StatDist test = new StatDist();
double Avg = test.Average();
However, if I want to also write a general purpose Average function in
the same class, I'd want to overload the function using 'public static
double' so that its usage would be:
double x[] = { ... };
double Avg = StatDist.Average(x);
Is it a good (or bad) idea to overload the function and make one of them
static all in the same class?
Regards,
Schiz
Jon Skeet [C# MVP] - 03 Mar 2008 16:37 GMT
> Just to continue this thread for a moment...
>
[quoted text clipped - 15 lines]
> Is it a good (or bad) idea to overload the function and make one of them
> static all in the same class?
I think it's reasonable in some cases. If you have a look at
Regex.Replace, it has exactly that sort of thing - various overloads,
some of which are static method and take a pattern, and some of which
are instance methods which use the target regular expression for the
pattern.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Schizoid Man - 03 Mar 2008 22:48 GMT
>> Just to continue this thread for a moment...
>>
[quoted text clipped - 21 lines]
> are instance methods which use the target regular expression for the
> pattern.
Thank you.
> Thank you all for the replies - I really appreciate it. I have a C++
> background and am preparing for an interview.
[quoted text clipped - 14 lines]
>
> Thanks again.
C++ uses static in *exactly* the same way. From the Visual C++ Language
Reference:
"When modifying a data member in a class declaration, the static keyword
specifies that one copy of the member is shared by all instances of the
class. When modifying a member function in a class declaration, the static
keyword specifies that the function accesses only static members."
Of course this is highly inaccurate. Static member functions can access
non-static members, both functions and data, as long as an instance of the
class is referenced in the process. Since the static member function is a
member of the class, it can access private and protected members in this way
as well.