|
Hi Nicholas, that's a very interesting, and appreciated, response, thanks.
I am definitely a devotee of the cult whose mantra is: "declared accessibility keeps you virgin."
I studied the MSDN page you kindly sent me a link to: the word 'static does not appear in it; the distinction between 'private and 'internal mentioned there applies to classes, and structs: "Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified." The example I showed uses variables. But, I did find that page worth studying, and bookmarking, for future reference !
Given these two declarations in a Form class' scope:
static bool notAvailableOutsideFormClassScope1 = true;
private static bool notAvailableOutsideFormClassScope2 = true;
There is no difference in accessibility/behavior outside/inside the Form class' scope.
I've actually gone to the trouble, just to make sure, of testing (code on request) if there's any difference in accessibility/behavior.
In externally declared classes, one static, the other public, neither the static class, or the public class, can access those static bool, form class' scoped, variables. As you would expect, both the static class, and an instance of the public class created in the Form's scope, where those variables are declared, can use/access (set, get) those variables.
So, I see no evidence for your assertion that a static variable declared without access-modifier is, by default, 'internal, and not 'private.
ReSharper 8: Resharper/Options/Code Editing/C#/Formatting Style/Other/Modifiers dialog ... I note that I have both options, "Use explicit internal modifier," and "Use explicit private modifier:" enabled.
The default behavior in ReSharper 8, with these options enabled, is to prepend the 'private access-modifier for a static variable, after you type it.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 6-Sep-13 1:29am.
|
|
|
|
|
|
Hi Nicholas,
I am curious now: in what circumstances have you ever used a static class, struct, or fields, or method, defined in the scope of a Form's class, and either made it private by declaring it private, or let it become private by default when you left off the access-modifier ?
I have never found a reason to do that, myself, but I suspect there are reasons for doing it under some circumstances that I'm not aware of ... and, I'd like to be aware of what possible use a private static something-or-other could be !
fyi: I went into ReSharper 8, and changed the modifier list so 'internal was at the top of the list. Declaring a static boolean variable in a Form: ReSharper 8 prepended the 'private access-modifier as soon as I completed the declaration.
It is good to learn new things, and it is good to have cause to question what one takes for granted, so I thank you for motivating me to revisit these aspects of .NET
yours, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Hey Bill
BillWoodruff wrote: I am curious now: in what circumstances have you ever used a static class, struct, or fields, or method, defined in the scope of a Form's class, and either made it private by declaring it private, or let it become private by default when you left off the access-modifier ?
There are things where it makes sense to declare something as private static. And I guess if you let it default let it become private or you explicitly declare it as private is just a preference... Where mine is to explicitly tell me and everyone else which visibility I am aiming for (private, internal, protected or public).
In our code the tracer for Log4net is declared as such. Because you want to be able to log in both static and non-static methods through it, but you don't want any other class to log through that same logger.
So in this case: The tracer instance of the form is declared as private static. So you're able to use the tracer in methods of the form to log information. Sure, as long as you don't need static methods in the form class you could also declare it without the static modifier. However the tracer is declared in every class in the same manner so why bother to change it and change it back when you happen to use the instance in a static method?
I don't know about other usages for such a thing on top of my head but I guess there might be some
BillWoodruff wrote: fyi: I went into ReSharper 8, and changed the modifier list so 'internal was at the top of the list. Declaring a static boolean variable in a Form: ReSharper 8 prepended the 'private access-modifier as soon as I completed the declaration.
Yeah, there are a lot of options for Resharper. But I like it because I don't have to think about formatting my code
yours, Nicholas
|
|
|
|
|
Well if all you're writing is front-end stuff, then you wouldn't have many public members anyway. I write mostly back-end library stuff so a great many of my members are public static methods, but not many fields.
A few examples:
public static readonly System.Type BaseType = typeof(T) ;
public static readonly Rational MaxValue = new Rational ( decimal.MaxValue , 1M ) ;
public static event ErrorDelegate OnError ;
public static ValueOf<T> operator + ( ValueOf<T> Op1 , ValueOf<T> Op2 ) ...
public static System.Reflection.PropertyInfo CommandTextAttributeProperty { get ; private set ; }
Consistency allowed me to find these easily.
|
|
|
|
|
i suggest frist one style.
|
|
|
|
|
I always like to use the access modifier first.
|
|
|
|
|
I'm with Richard Deeming here, I use the first method myself. As Richard said, consistency is the key!
|
|
|
|
|
public static is more poetic. We've been using it for a decade now. Why change it?
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
Vunic wrote: public static is more poetic. Just curious: is private static any less poetic ?
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Private static is still poetic.
Just static public, static private looked reverse-poetic.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
|
I have this code:
public void mtdProgressbar() {
prgsBar.IsIndeterminate = false;
prgsBar.Orientation = Orientation.Horizontal;
prgsBar.Minimum = 0;
prgsBar.Maximum = short.MaxValue;
prgsBar.Value = 0;
double value = 0;
prgsBar.Visibility = Visibility;
UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(prgsBar.SetValue);
do
{
value += 1;
Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background,new object[] { ProgressBar.ValueProperty, value });
}
while (prgsBar.Value != prgsBar.Maximum);
prgsBar.Visibility = Visibility.Hidden;
}
But i can not create the Thread do fill progressbar, do not work.
The code:
.
.
.
else{
System.Threading.Thread trd = new System.Threading.Thread(new System.Threading.ThreadStart(this.mtdProgressbar));
trd.IsBackground = true;
trd.Start();
mtdTest();
}
I'm using C# and Wpf
|
|
|
|
|
Threads can be tricky, what you are running into is a problem with access.. threads by default can not access the ui to update a progress bar because that may create a deadlock.
For the background worker there is a function built in for report progress, but it is limited to only allow for simple updates.
You can however, get around this requirement by doing
.Invoke((Action)delegate() which allows safe access to the ui through a delegate.
I have used this method to update multiple labels, etc.
That should do the trick.
=)
|
|
|
|
|
Forbiddenx wrote: You can however, get around this requirement by doing
.Invoke((Action)delegate() which allows safe access to the ui through a delegate. Hi, isn't the OP already doing this in his code:
do
{
value += 1;
Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background,new object[] { ProgressBar.ValueProperty, value });
} ?
Of course, the OP didn't disclose the code for 'updatePbDelegate, or show where it's created. In this case I think the problem is elsewhere (see Dave K.'s response).
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Yes, I do see invoke but it does not look like its used correctly.
It looks to me like his code is trying to access the progress bar ui directly and outside of the invoke.
It looks like he is setting a lot of values, my guess is some of those values are on the ui and that is what is crashing everything.
I think he is going to have to re-write how this works..
=)
|
|
|
|
|
You don't put the progress bar in the background thread. It MUST stay on the UI (startup) thread. Your work goes in the background thread and then Invokes a method that updates the progress bar on the UI thread.
|
|
|
|
|
See here[^]
It's from one of the CP members... (btw)
hope this helps
|
|
|
|
|
I'm in my third year of a software development course and will soon be tasked with completing a project to demonstrate my knowledge so far in programming.
I have decided to pick c# as the language as I'm more confident with it and my ideas so far are either a website with a database and/or a shopping cart or else an application like a movie library that has a database and capabilities to update info from the web.
The spec for the project is vague in terms of features and functions as I'm just going by what I've learned in the last three years.
I would be grateful if anyone could give me some feedback on my ideas or any new ideas they may have.
Thanks for your time
|
|
|
|
|
Depending on how long you have....
C# and unity go nice together..
=)
|
|
|
|
|
Choose something that you have an interest in, so that your knowledge can help you design the program. It is impossible to suggest much more as we have no idea of your experience. You could look at the CodeProject Articles section[^] for some further ideas.
Veni, vidi, abiit domum
|
|
|
|
|
Go with Richards idea, my son did his on scuba diving, his hobby at the time.
If you can't think of something then try and find a friend who runs a small business and ask then for their most painful paperwork job then try and automate it. Beware you may lose that friend, birthing your first LOB solution is a painful exercise for all involved.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi johnmolo,
You can chose any one of the projects you mentioned.But take care of following points.
1.Use coding standards.
2.You should include all the OOPs concept in your project.
3.Database standards should be followed.
4.Use MVC architecture for designing.
5.Choose a professional looking design, no need for a complex design.
6.Try not to use any external API's since it may cause problem at any time.
Happy coding and wish you all the best for your project
|
|
|
|
|
Quote: 6.Try not to use any external API's since it may cause problem at any time.
What if someone would like to do payment integration. External API is the only bridge that can help Software developers to work beyond the limit of their existing software. You can add more functionality and more features. My personal opinion is to use already build application (API) instead of rebuilding the same. If we have Image processing library why should i create my own for even my small project.
I am not against you but always there is two side of coin. You may have some bad experience with external API's.
Thanks
-Amit Gajjar
|
|
|
|
|
Hi Amit,
Thanks to point out the mistake.What i really meant was not to use complex APIs since it may affect working of project ( I had a bad experience ).
|
|
|
|
|