. NET basic collection Part 2:. NET basic concepts (Part 2)

Source: Internet
Author: User

In the first article of the. NET basic collection series:. NET basic concepts, I mentioned ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Object-oriented Thinking
Differences between classes and objects
Private, protected, internal, publicModifier
Attribute andGet, set
Static classes and member functions are both staticCertificate ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • So I will continue to talk about these basic concepts and hope to express my understanding and the necessity to easily remember and use them --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
  • Constructors are also useful
    Overloading and rewriting are also involved.
    The interface is coming, and the abstraction is coming.
    Let's talk about the factory. The role of the keyword "this" and "base"Indexer and iterator
  • Certificate ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  •  
  • (6)Constructors are also useful 
  • In fact, if you see a constructor, someone can say its role in one sentence, that is, the constructor is used to create an instance of the class and initialize the instance. By passing different parameters, different instance initialization operations can be performed. To put it bluntly, this is done. Due to the strict requirements of the c # compiler, the field of value type (In c #, data structures are mainly divided into two categories: value type, which refers to simple type, integer, Boolean... and the structure type and enumeration type. The other is the reference type, including the class type, array type, proxy type, and interface type.Must be initialized before the constructor ends. when an object is created, a method is automatically executed, which is the constructor, let me talk about some precautions for using constructors: 1. when no constructor is available, the c # compiler automatically provides a default constructor, that is, a constructor without any parameters. Remember that the default constructor is public. when there is a constructor, in this case, the constructor is always called, and the compiler will not provide the default constructor 3. when there are multiple constructors, multiple constructors are differentiated by different signatures. When using them, the rules of method overloading are used, the compiler does not provide the default constructor. The constructor is similar to the method in the class. It is also a function. However, its name must be the same as that of the class, and the constructor has no return value, this is the difference between the name of a common function and the default constructor without parameters.  Code:
    UsingSystem;
    UsingSystem. Collections. Generic;
    UsingSystem. Linq;
    UsingSystem. Text;

    NamespaceGz
    {
    ClassProgram
    {
    Static VoidMain (String[] Args)
    {
    Console. WriteLine ("America News Online started. The following is the latest news");
    Console. WriteLine (APeople. name+ "Post");
    News news= NewNews ();
    News. ShowNews ();
    Console. WriteLine ("China News Broadcast starts. The following is the latest news.");
    Console. WriteLine (HPeople. name+ "Post");
    News. ShowNews ();
    Console. ReadLine ();

    }
    }
    ClassNews
    {
    Private StringNewTitle= "Bin Laden was shot!";
    Internal VoidShowNews ()
    {
    Console. WriteLine (NewTitle );
    }
    }
    //Static constructors of the Obama class. Users initialize static members.
    ClassAPeople
    {
    Internal Static StringName;
    StaticAPeople ()
    {
    Name= "Obama";
    }
    }
    //The Hu class private constructor cannot create an instance outside the class.
    ClassHPeople
    {
    Internal Static
  • 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.