472,119 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

private static

What is the purpose or difference between
private static and private method in non-static class?
Nov 18 '05 #1
5 1541
If I understand you correctly, you want to know the difference between a
private static method in a non-static class, and a private non-static method
in a non-static class? If I am correct in my understanding of your
question...

A non-static class is a class which requires instantiation to use. A
non-static member of a class is a member which requires an instantiation of
its host class to use. A static member of a class is a member which does NOT
require an instantiation of its host class to use.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"TomislaW" <to*********@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
What is the purpose or difference between
private static and private method in non-static class?

Nov 18 '05 #2
Kevin's right and to build on it...a public static method in an instance
class often provides utility functionality to the outside which somehow
relates to the class. For example, given a User class, you might have a
public static method to say, get a user class by user id:

public class User{
private int userId...

public static User GetUserById(int userId){
}
}

A private static method in an instance class pretty much does the same, but
only exposes the functionality internally to the class. In my experience,
the need for this doesn't come up too often. I've probably used it the most
when I provider overloads of public statics and they all use the same
private static, that for some reason I don't want exposed.. Just my $0.02

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
If I understand you correctly, you want to know the difference between a
private static method in a non-static class, and a private non-static method in a non-static class? If I am correct in my understanding of your
question...

A non-static class is a class which requires instantiation to use. A
non-static member of a class is a member which requires an instantiation of its host class to use. A static member of a class is a member which does NOT require an instantiation of its host class to use.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"TomislaW" <to*********@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
What is the purpose or difference between
private static and private method in non-static class?


Nov 18 '05 #3
I think the confusion lies in that a static method, as you say, does not
require an instantiation of the host class, but being private, nothing can
access it but an instantiation of the host?!

Therefore, would it be right to suggest that there's never a reason for
using private and static together in declaring a function?
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
If I understand you correctly, you want to know the difference between a
private static method in a non-static class, and a private non-static
method
in a non-static class? If I am correct in my understanding of your
question...

A non-static class is a class which requires instantiation to use. A
non-static member of a class is a member which requires an instantiation
of
its host class to use. A static member of a class is a member which does
NOT
require an instantiation of its host class to use.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"TomislaW" <to*********@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
What is the purpose or difference between
private static and private method in non-static class?


Nov 18 '05 #4
Dan Bass wrote:
I think the confusion lies in that a static method, as you say, does
not require an instantiation of the host class, but being private,
nothing can access it but an instantiation of the host?!

Therefore, would it be right to suggest that there's never a reason
for using private and static together in declaring a function?


You can call private static methods from other static methods
(possibly public) in that same class.

Hans Kesting
Nov 18 '05 #5
Hans,

For some reason I thought this wouldn't compile because the statics weren't
both public!
cheers for that.

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:Ob**************@TK2MSFTNGP15.phx.gbl...
Dan Bass wrote:
I think the confusion lies in that a static method, as you say, does
not require an instantiation of the host class, but being private,
nothing can access it but an instantiation of the host?!

Therefore, would it be right to suggest that there's never a reason
for using private and static together in declaring a function?


You can call private static methods from other static methods
(possibly public) in that same class.

Hans Kesting

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by IHateSuperman | last post: by
34 posts views Thread by Andy | last post: by
1 post views Thread by romand | last post: by
reply views Thread by leo001 | last post: by

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.