|
-
May 23rd, 2006, 02:42 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] static vs non static
Hi,
What is differences between a static function and non static? Except that static function need not to instanciate. Any idea or input?
Thanks,
Popskie
-
May 23rd, 2006, 03:02 AM
#2
Re: static vs non static
No, that is the difference 
Like you said static function in a class does not require an instance of the class, you just qualify it with the class name and call it.
Also there is obviously no this pointer available as that would require a class instance. Usually you'd pass an instance to the function, like any of the static functions in the String class for example.
-
May 23rd, 2006, 08:16 PM
#3
Thread Starter
Fanatic Member
Re: static vs non static
In memory consumption? If thier is no difference why static keyword evolved in so many programming languages?
-
May 23rd, 2006, 08:44 PM
#4
Re: static vs non static
The use of the "static" keyword is not just a convenience so you don't have to create an instance. There is a conceptual difference between static members and non-static members that too many people seem to ignore. Logically a static member is a member of the class itself, while a non-static member is a member of a specific instance. Take the System.IO.File class for instance. All of its members are static because they all do things that relate to files in the file system, but not to any specific File object within your application. Also take the String class. It has members like Format and Join that do not act on any single specific instance so logically they should be, and are static members. Other members like IndexOf or Split do act on a specific instance so logically they should be, and are, instance members. Generally speaking any method could be made static or not, but one choice is almost always logically more sound than the other.
-
May 23rd, 2006, 09:37 PM
#5
Thread Starter
Fanatic Member
Re: static vs non static
thanks penagate and jm for the info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|