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

public static and static

Hi,

What's the difference "public static" and "static"?
Do we have "protected static" and "private static"? If we do, in what
situation will we apply them?
Thanks for help.

Jason
Nov 17 '05 #1
2 1410
Jason.... If you do not explicitly declare the access modifier, then the
default
accessibility for class and struct members is private. private static
members are
useful for thread safe identifiers.

// static stuff
private static int uniqueID= 0;
private static int GetUniqueID()
{
lock(typeof(TestStatic))
{
return uniqueID++; // returns zero at start
}
}

Alternatively you can lock on a syncLock object.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #2
See inline
"Jason Huang" <Ja************@hotmail.com> schrieb im Newsbeitrag
news:uE*************@tk2msftngp13.phx.gbl...
Hi,

What's the difference "public static" and "static"?
Do we have "protected static" and "private static"?
access modifiers (public, protects ...) and the static modifier are
independent.
You can combine static with any valid combinition of access modifiers.
Since private is default (where applicable), "private static" is the same as
"static".
If we do, in what situation will we apply them?
Simply, if a member should be private resp. protected and also static.
If you don't find a situation, don't use them ;-)
Thanks for help.

Jason

Nov 17 '05 #3

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

Similar topics

3
by: Steve | last post by:
Visual Studio 2003 .NET / C# I have a treeview object on a form which acts as the main menu controller for my application. the treeview is always in sight, and the form it is on acts as the...
0
by: john bailo | last post by:
I am attempting to create a c# program to iterate through the messages in an Outlook/Exchange public folder and extract the headers. My apologies to the VB/VBA groups, but you seem to have more...
6
by: GG | last post by:
Is this public static method thread safe. //Receives a file name as a parameter //and returns the contents of that file as a string public static string FileToStr(string fileName) { FileStream...
6
by: z_learning_tester | last post by:
Quick question- What happens if you have a private class with a public static method? Can you still say the following? Lets say you are making this call from another class, say class2... int...
5
by: rettigcd | last post by:
I have several classes that all have the same static member: class A{ public static string Table = "TableA"; } class B{ public static string Table = "TableB"; }
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
5
by: selimsivad83 | last post by:
Hi everyone, Thinking in Java, 4th edition, p 232: ... if you don't put an access specifier for class access, it defaults to package access. ... However, if a static member of that class is...
15
by: archana | last post by:
Hi all, can anyone tell me differene between public static and private static method. how they are allocated and access?. thanks in advance.
1
nomad
by: nomad | last post by:
Hi everyone: This project is driving me crazy and I need some help. I would post it here but I have worked so hard on it that I don't want someone else in my class to steal it. So if I can pm it...
6
by: stoogots2 | last post by:
am using Visual Studio 2003, .Net Framework 1.1, C#. I get a SystemNullReferenceException when trying to do a hashtable.add(string,string) from a login page, and I do not understand why because all...
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: 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
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?
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.