By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

private static

P: n/a
What is the purpose or difference between
private static and private method in non-static class?
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.