Chapter 3 induction of knowledge points and Chapter 3 knowledge points

Source: Internet
Author: User

Chapter 3 induction of knowledge points and Chapter 3 knowledge points

1. Object Initiator

Initialize the object directly when calling the constructor.

 

public class Student{    public string Name;    public int Age;    public bool Gender;}Student stu=new Student{Name="zhangsan",Age=10,Gender=false};

Equivalent:

Student stu=new Student();stu.Name="zhangsan";stu.Age=10;stu.Gender=false;


2. this and base

This is the reference class instance itself.

 

public class Student{  string name;  public Test(string name){this.name=name;}}


Base function: 1. Access the overloaded base class method member from the subclass 2. Call the construction method of the base class

Reference the example in the book:

public class Asset{   public string name;   public virtual decimal Liability{ get { return 0; } }}public class Home : Asset{   public decimal Mortgage;    public override decimal Liability    {        get { return base.Liability + Mortgage; }    }}


3. packing and unpacking

Packing is to convert the value type to the reference type.

Int num = 10;

Object obj = x; // boxed int type

The case is to convert the reference type to the value type.

Object obj = 10;

Int num = (int) obj;

The essence of packing and unpacking is copying: Packing refers to copying a value-type instance to a new object, and disassembling refers to copying the content of the object back to a value-type instance.

 

4. covariant and Inverter

Covariant: Assume that A is A subclass of B. If C <A> can be referenced and converted to C <B>, C is called A covariant class.

IAbc <string> a = ...;

IAbc <object> B =;

IAbc <T> is a covariant class.

Inverter: Assume that A is A subclass of B. If C <B> can be referenced and converted to C <A>, C is called an inverter class.

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.