|
I write a lot of private statics -- most access private static data.
I see no reason to make a method non-static just because it's private.
|
|
|
|
|
As others already said, I choose static to indicate the method needs no data or has no state, other than static data fields.
|
|
|
|
|
It looks like static is being used to document methods that did not interact with the class' internal variables; I was just curious if there was any advantage that went with it. Thanks for the responses.
|
|
|
|
|
Gregory.Gadow wrote: It looks like static is being used to document methods that did not interact with the class' internal variables
I assume by "class" you mean "instance" here. Static methods can access class-level (i.e. static) variables. Although you then need to think carefully about threading issues if these static variables are being changed by different instances.
|
|
|
|
|
Yes, the instance's variables
The class has no static storage, and all of the static methods are along the lines of "perform a calculation on the parameter and return the result."
|
|
|
|
|
David Skelly wrote: think carefully about threading issues
Oh, yeah, there's that -- static methods are thread-safe, right? Maybe in some cases you don't need thread-safety, so making the method non-static will allow increased parallelism?
|
|
|
|
|
PIEBALDconsult wrote: static methods are thread-safe, right?
yes, if the documentation for a particular class says so. Otherwise no.
The typical .NET class does that, as you well know.
|
|
|
|
|
I found this interesting piece on the msdn site -
"A call to a static method generates a call instruction in Microsoft intermediate language (MSIL), whereas a call to an instance method generates a callvirt instruction, which also checks for a null object references. However, most of the time the performance difference between the two is not significant."
This is contrary to the belief that static methods can improve performance in certain situations.
So I suppose it's just a matter of usage really.
|
|
|
|
|
Abhinav S wrote: This is contrary to the belief that static methods can improve performance in certain situations.
Why contrary? Sounds like it says static methods are faster. Granted the difference is not significant most of the time (i.e., it is significant some of the time).
|
|
|
|
|
when is that local variables are created and destroyed ,C#?
thanks.
|
|
|
|
|
You really need to buy this book[^] and read it. The point of the forums is not to teach people the basics of the language - the forums are here to help people with specific problems they may have.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
What difference does it make?
|
|
|
|
|
it may be important when a method needs huge amounts of local variables: it may work well when they get allocated and freed by the smallest code block that contains them, it may throw a StackOverflowException when all of them get allocated upfront.
|
|
|
|
|
Luc Pattyn wrote: when a method needs huge amounts of local variables
Refactor?
|
|
|
|
|
Isn't that going to use more stack space? Return addresses, and so forth...
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Yeah, well, you could delegate some data to local variables in a different method, executed by some other thread. So basically implement an in-stack database, using Invoke to call on a single GetSet() method. But then that may be over-engineering the situation a bit.
|
|
|
|
|
Would be a nice answer to stump his teacher and set a new bar for homework, though
I are Troll
|
|
|
|
|
Remind me to suggest it at the next code review...
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
I need some quick direction, how to - overview. I am relatively new to C# and Windows Form Programming but excited and interested in consuming everything I can. I need some direction for my research and design.
I have a panel control.
Within the panel control I have 4 Text Boxes, a DataGridView, a few labels etc...
I have an xml file source.
I have a main source windows form.
I want to have a drop down box on the Windows Form that has a list of items from the xml file.
Once I select the item from the down box I want to copy (instantiate) the panel with all of the controls within the panel, and then populate them with the rest of the data from the xml dataset already loaded.
I have done all of the code up to the instantiating and copying the panel with its controls...
Is there a better way to do this? keywords i can research, a little direction would be so helpful! Thanks!
|
|
|
|
|
List the three ways that data can be transmitted within the parameters provide the associated keywords.in C#
thank you.
|
|
|
|
|
toto_2010 wrote: List the three ways that data can be transmitted
Telephone
Telegraph
Tell-a-mother-in-law
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
That was a trick question. There are many more ways:
Telex
Tell-ex-wife
...
|
|
|
|
|
List three ways you can get your homework done without asking in a forum.
|
|
|
|
|
.Write
.WriteLine
Left as an exercise.
|
|
|
|
|
Backwards.
Forwards.
Sideways.
Hope this post was as helpful as much as your question was not a homework assignment!
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|