C # differences between static and non-static

Source: Internet
Author: User

During the interview this afternoon, HR asked: What are the differences between static or static methods and non-static methods in C?
My answer is that static calls can be called directly instead of static ones that need to be instantiated. HR said that everyone knows this. What I ask is the essential difference.
I was depressed at the time. I only had 8 months of programming experience and almost never used static classes or methods. I only knew how to use them,
So I could only answer the question and asked a few questions later. The answer was unsatisfactory and the answer was rejected ..

After going home, I checked on the Internet and found that one needs to be instantiated and the other needs to be called directly. This is accepted as no problem. I will paste the rest.
For reference

Static is a class definition, and dynamic is an object definition.
Classes must be defined before objects can be defined. Therefore, static objects must be prior to dynamic objects, and only one static object can be created.

========================================================== ======

It is loaded once during static running.
Non-static operations are loaded every time
The static lifecycle is the same as that of the class.

========================================================== ========

Static variables and Methods belong to the class and are created when the class is called;
There is only one copy in the memory and will not increase with the increase of the object;
Dynamic variables and Methods belong to objects and will increase with the increase of objects.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.