|
Well, in Object Oriented programming to tend to have no static methods. Usually, static methods are shortcuts for constructors or for accessing singletons.
With static classes you cannot do virtual overloading which is a very important tool in OO.
While designing static method you should take good care of making them thread-safe. This is done by two ways: make the class have no static field or lock the class type before doing something.
Cheers
Jonathan de Halleux.
www.dotnetwiki.org
|
|
|
|
|
Matthew Hazlett wrote:
As I see it you only need to use non-static if you need to instance a class as an object. But I am at a loss to see when you would absolutly need to use a non-static method.
Ummm... Gosh, it's the first time I've seen that question - usually it's the other way round.
Let's say you have a class that represents a customer - You don't expect to only ever have one customer do you? Each customer is represented by an instance of the class. A static should only be used when it is going to be common to all customers. So, for instance a property called CustomerAccount should be a non-static because each customer has a different account number. However you may have a method called GenerateNewAccountNumber() which would be static because its result is not dependent on any single instance of the customer class. It might be combined with a static member variable (field) called NextAccountNumber so that each time it called the field is updated so that each subsequent call will generate a unique Account number (as you don't want two customers to have the same Account Number)
Does this help?
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Ok, then its kinda like I thought.
A static object is just a single entry analigus to the static variables in VB.
Is this to say if you have a non-static object like "Mailbox" and then create the object 5 times, If the object contains static methods each copy of the object will use the same method "prototype" (but diffrent data) ?
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Matthew Hazlett wrote:
If the object contains static methods each copy of the object will use the same method "prototype" (but diffrent data) ?
No, the static methods (or properties) can only access static data (fields/member variables) in the class.
Non-static methods (or properties) can access both static and non-static data in the class.
The static data in the class exists only once for the entire application, the non-static data applies once for each instance of the class because it may be different for each instance of the class.
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Lemme see if I got this,
from what your saying you can't mix static and non-static, right?
If this is true its much simpler then I thought...
So, my five Mailbox objects would need all the methods to be non-static.
Could those methods then call static methods (in another class) to minipulate data?
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
You can mix static and non-static...
class Customer
{
private static int _nextAccountNumber = 0;
private int _accountNumber;
public Customer()
{
_accountNumber = GenerateNextAccountNumber();
}
public Customer(int accountNumber)
{
_accountNumber = accountNumber;
}
protected static int GenerateNextAccountNumber()
{
return _nextAccountNumber++;
}
public int AccountNumber
{
get
{
return _accountNumber;
}
}
}
Do you see how it works? This is just one example of how you might use a static member variable and method mixed in a class with non-statics also.
From a static method you cannot access non-static members because you don't have any particular instance as a reference. From a non-static method you can access anything you like because you have access to the non-static member variables as you have a reference to an instance and you can access the static member variables because it doesn't matter one way or the other if you have a reference to a particular instance or not.
Does this help clear things up?
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
I see, thank you.
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Hey
I got a ListView(as controller) there I change the background color of induvidual items with theres sub items.
I use this
addItem.BackColor = Color.DodgerBlue;
addItem.ForeColor = Color.White;
This ListView is in a Client application.
When i starts up 3 clients and one server on my computer and then login on the fisrt client, the ListView(as controller) is updating and al looks good,
but when i login on the second client this client's listwiev is not drawing the listview(as controller) items/subitems right. Its just painting some of the subitems.
When i drag a window over the clients listview(as controller) it updates it self and i can se the right bakground colors again.
How do i fix this problem? i have tryed to use update and so on on the controler(with the listView) but its not fix the problem.
Pleas any ides?
//Jimmy
|
|
|
|
|
I've been looking at the platform SDK, and what I have at the moment in terms of code. I think it was actualy solved a while ago, it just didn't match what the documentation states.
FOr some reason, the zero value of the STRRET that is returned from my method appears to be correct and functioning.
The string returns a full path if I set the NORMAL flag, with a square charachter on the end, and simply a square charachter if I set the INFOLDER.
The problem I have is, if I am getting the object name, where is the square charachter comming from? How does the full path that is returned get generated? The square value would be where the name of the object should be, say a file or something. The odd thing is, it appears to not realise it's actualy looking for a folder.
Normal Flag:
@"C:\Documents and Settings\All Users\Desktop\?"
INFOLDER Flag:
@"?"
where the question mark is the square charachter.
Any ideas why this is the case? And why I can't seem to get the folder value returned?
Cheers
Cata
|
|
|
|
|
|
This little sqaure character is most likely the string termination character, ASCII value 0.
It is VERY common throught the Win32 API to pass strings with a null termination character, ASCII 0.
RageInTheMachine9532
|
|
|
|
|
So if I correctly understand the post an SDK function is called which returns a STRRET that ends with a "square" character instead of an expected "question mark."
Research into [C# Spec Escape Sequences] reveals "\?" is most likely not a valid escape sequence for a "square" character.
Additionally, the @"" preceeding the string means to treat the string verbatim, i.e. to not process escape sequences.
Have you tried to remove the verbatim @"" and use escape sequences, i.e. each \ in the call string becomes \\ ?
What SDK function are you calling? Can you post a code example?
Sincerely,
-Ron
|
|
|
|
|
Hi Guys
I need your help. (please...) I don't know if my question is on the correct newsgroup.
I created a C# program that listen to another computer get the data and save it to SQL server databse using his port number. I need to run this program into the windows service so that it will run continously.
I don't want to use the windows scheduler. I want to create a C# program that will function as service and run my program at the same time.
Please any help or tutorials would of great help tome.
thanks in advance, specially the time.
Dabus
|
|
|
|
|
Use the search bar at the top of page and search this site to find some arrticles about how to create a windows service. Its very easy with C#.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
http://www.codeproject.com/csharp/csharpsvclesson1.asp
http://www.codeproject.com/dotnet/simplewindowsservice.asp
I think these are ones...
|
|
|
|
|
I've been using the AxWebBrowser control for some time now. Lately though, it's been giving me this error message when I exit the program (after debugging).
<br />
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in system.windows.forms.dll<br />
<br />
Additional information: Unable to get the window handle for the 'AxWebBrowser' control. Windowless ActiveX controls are not supported.<br />
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
is it posible to catch some console input before drawing it on screen using some API functions?
thank u for help!
|
|
|
|
|
|
FileIOPermissins this class give me permissions on my application but not change permissions Physically on my drive i need to change the permissions on any folder on my drive Physically even if i close the application
|
|
|
|
|
There is nothing native in the .NET Framework to modify the Access Control Lists on Files, as far as I can find. You would have to use calls into the API to accomplish this. It would require writing up a couple dozen structure and function headers:
LookupAccountName, InitializeSecurityDescriptor, GetSecurityDescriptorDacl, GetFileSecurityN, GetFileSecurity, GetAclInformation, EqualSid, GetLengthSid, InitializeAcl, GetAce, AddAce, AddAccessAllowedAce, AddAccessDeniedAce, SetSecurityDescriptorDacl, SetFileSecurity, ...
then there's the structures that go along with them:
SECURITY_DESCRIPTOR, ACL_SIZE_INFORMATION, ACL, ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, ACE_HEADER
RageInTheMachine9532
|
|
|
|
|
|
hi i have A Room with diementions
z=-80 to z=286
y=-66 to y=5
x=20 to x=100
i dont know what is the best type of lighting and where to put it and what is the recommended number of lighting??
|
|
|
|
|
I'm currently writing a painting method of an custom usercontrol. Is there a way to determine if the control is in designing state or at useual (runtime state) ?
public void PaintObject()
{
if (DESIGNTIME == true) DrawRectArountControl();
else DoUsualDrawing();
}
|
|
|
|
|
Sure, try using base.DesignMode().
RageInTheMachine9532
|
|
|
|
|
public void PaintObject()
{
if (true == this.DesignMode) DrawRectArountControl();
else DoUsualDrawing();
}
|
|
|
|