|
You would want to use static methods when it wouldn't make sense to create an instance fo the class for it.
For example:
<br />
Math myMath = new Math();<br />
myPath.sqrt(3.14);<br />
Wouldn't make sense. You don't want to have to create a Math object just to use the square root function. Instead, you make the square root function a static method of the Math class, so you can just say
Math.sqrt(3.14);
Hope that helps some.
using System.People;
Person me = new Person();
me.Certifications = null;
me.Experience = little;
me.WantsToLearn = true;
me.InSchool = true;
me.AskQuestions("C# .NET 2003");
|
|
|
|
|
hi MartyExodus,
MartyExodus wrote: Hope that helps some.
yeah, It's helpful to me.
more and more answers help me understand when use a static method.
Thanks a lot.
|
|
|
|
|
A good time to 'investigate' using a static method is if no 'instance' state needs to be persisted, read, or changed in the method.
|
|
|
|
|
hi A.A.
A.A. wrote: no 'instance' state needs to be persisted, read, or changed in the method.
is detailed with
Christian Graus wrote: static objects are not tied to an instance
Thanks a lot.
|
|
|
|
|
I am developing a Windows Service under VS 2005. Within the code some shared network directories have to be enumerated but when the code attempts to verify the existence of any one of those directories with code similar to: Directory.Exists("\\somedir\subdir") the function returns false every time apparently because network authentication is not automatically done by Directory.Exists. Can anyone point me in the write direction (e.g. example) of what I must do programatically to ensure the network authentication is in place to allow this command to succeed in a Windows Service when using UNC names?
Thank you...
|
|
|
|
|
Never mind. Just had to set up the proper service logon.
|
|
|
|
|
|
Have a look in the obj folder and see for yourself. The difference is, the C# compiler isn't compiling an executable file, just MSIL.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: look in the obj folder
Nothing too exciting in the obj folders of my VS2005 projects. Just a ton of intermediate files
I'd like to help but I am too lazy to Google it for you.
|
|
|
|
|
Ok, I don't mind helping out here, and have gotten help here, BUT it is frustrating when people ask the SAME QUESTION over and over.
You asked basically this SAME question two days ago. What part of C# DOES NOT GENERATE OBJ FILES did you not understand? Do some reading on the environment on your own. This is BASIC to the .NET platform.
This is C# w/.NET and NOT C or C++. Get over it or code in those languages.
Sorry for the rant guys.
WhiteWizard
aka Gandalf
|
|
|
|
|
MCSD-Gandalf wrote: You asked basically this SAME question two days ago
Don't worry - That happens a lot!
MCSD-Gandalf wrote: Sorry for the rant guys.
That's okay - Some of the people here just seem to provoke rants.
|
|
|
|
|
Colin Angus Mackay wrote: MCSD-Gandalf wrote:
You asked basically this SAME question two days ago
It is amazing the amount of impatience some people have when waiting for their questions to be answered. I am starting to just simply say to look at my sig
I'd like to help but I am too lazy to Google it for you.
|
|
|
|
|
Its in the book on page 35. Right under the brief introduction to MSIM.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
i am working on a project in which i have to compile each file of project on separate computer of LAN then i have to generate exe combining all the compiled results..........but i am not getting any help how to do this......i just want to know what formate does c#.net generates which are then linked to generate the exe and where those files are stored........
|
|
|
|
|
I have a program that consists of a number of messages type. I am trying to ensure that all messages of a given type have a dedicated handler. Each message type has its own message handler.
I have created an interface base class which states all messages need a handler.
Each derived class should have a single event handler, therefore I used the static keyword so that it is common across all the derived classes i.e. a single handleMsg for all instances of the msg1 class.
So I implemented this:
interface baseMsg
{
void handleMsg ();
}
class msg1 : baseMsg
{
…
public static void handleMsg ()
{
Console.WriteLine ("msg1 Handled");
}
}
class msg2 : baseMsg
{
…
public static void handleMsg ()
{
Console.WriteLine ("msg2 Handled");
}
}
I am getting an error CS0536:
Error Message
'class' does not implement interface member 'interface member'. 'class member' is static, not public, or has the wrong return type
So I cannot implement it in the way I originally thought.
Does anyone have any suggestion on how I can achieve this?
Thanks,
LiamD
|
|
|
|
|
A singleton pattern for the event-handler class?
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
hi all,i have one function in my application where i have a button ,upon clicking i need it to produce a number 0001, the second time u run the form u will get 0002..and so on..its something like a receipt that auto run on numbers in sequence.. how do u do it?
|
|
|
|
|
use some form of storage (database, XML, flat text, whatever) to store the last-used number and load that each time the form starts.
-- modified at 6:28 Wednesday 26th July, 2006
|
|
|
|
|
I have Form, MdiContainer=true , adding two other forms in it, with webbrowser, listview and other controls, and then activating these forms, i can see repaiting hole form, so i did a stress test, and this repaiting really sucks, specialy forms are maximaised, take a look at my stress test:
http://jefis.suncity2k.com/Debug.rar
|
|
|
|
|
I don't really know what you are talking about. The two forms jumped back and forth so quickly I could not really see the screens. And my machine sucks.
|
|
|
|
|
hi
is there anyone know if microsoft visio can convert code to a uml class diagram and how visio does it ??
Allah give me love for all people , talent is Allah's gift
|
|
|
|
|
Can Visio do that ? I don't believe so...
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yes, its called reverse engineering.
|
|
|
|
|
Yes. But you must use "Visio for Enterprise Architect".
You can convert :
Code -> UML Diagram
UML Diagram -> Code
|
|
|
|
|
Visio had the ability to do this as far back as VB5 (or maybe 6).
For .NET, I would assume that visio uses reflection to look at the types defined in an assembly, and creates the UML shapes from the properties/methods defined.
|
|
|
|