Results 1 to 5 of 5

Thread: [RESOLVED] static vs non static

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Resolved [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

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: static vs non static

    In memory consumption? If thier is no difference why static keyword evolved in so many programming languages?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width