There are two types of constructor:Instance Constructor and Type Constructor(or so-called Static Constructor).

Instance Constructor

When use the new key word to create an instance of class, it will do:

  1. Calculate the size of the class, including the sync block and the type object pointer, so that it knows how much memory the instance needs.
  2. Allocate memory.
  3. Call the the constructor,and it will call the constructor of the base class before the current constructor do anything, and so on to the constructor of the Object class.Note that

Constructor is the only way to initialize a instance or a type, We may have seen codes like below:

class SomeClass
{
private int aField = ;
public SomeClass()
{ }
}

you may think aField is initialized outside the constructor, but this is just a syntactic trick of c#。The compiler will gen some IL codes to set aField to 5 inside the constructor, AND, if there are more than one constructors, each one will contain that piece of IL initailling codes.

Constructor in depth的更多相关文章

  1. js in depth: arrow function & prototype & this & constructor

    js in depth: arrow function & prototype & this & constructor https://developer.mozilla.o ...

  2. js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit

    js in depth: Object & Function & prototype & proto & constructor & classes inher ...

  3. Thread in depth 4:Synchronous primitives

    There are some synchronization primitives in .NET used to achieve thread synchronization Monitor c# ...

  4. 【D3D12学习手记】4.3.8 Create the Depth/Stencil Buffer and View

    我们现在需要创建深度/模板缓冲区. 如§4.1.5所述,深度缓冲区只是一个2D纹理,用于存储最近的可见对象的深度信息(如果使用模板(stencil),则也会存储模板信息). 纹理是一种GPU资源,因此 ...

  5. HOC in Depth

    HOC in Depth Higher-Order Components https://reactjs.org/docs/higher-order-components.html 1. wrappe ...

  6. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  7. 分析js中的constructor 和prototype

    在javascript的使用过程中,constructor 和prototype这两个概念是相当重要的,深入的理解这两个概念对理解js的一些核心概念非常的重要. 我们在定义函数的时候,函数定义的时候函 ...

  8. js中的constructor

    定义和用法 constructor 属性返回对创建此对象的 Date 函数的引用. 语法 object.constructor constructor属性不影响任何JavaScript的内部属性.in ...

  9. Java程序设计之Constructor

    插入段代码,下次回忆吧. 先新建一个Person类,代码如下: public class Person { private String name ; private int age; public ...

随机推荐

  1. Delphi、Lazarus保留字、关键字详解

    Delphi.Lazarus保留字.关键字详解 来自橙子,万一的博客以及其他地方 保留字:变量等标识符可以再使用: 关键字:有特定含义,不能再次重新定义: 修饰字:类似保留字的功能,也就是说可以重用 ...

  2. About how fast is fast enough for a web application?

    About how fast is fast enough for a web application? Here’s a quick overview of key performance metr ...

  3. mybatis 插入数据并返回主键值

    <insert id="insert" parameterType="com.pojo.TSubject" useGeneratedKeys=" ...

  4. sql复杂查询

    内连接 左外连接 Left Outer Join On  ,无论右边是否匹配到,左边的数据都在 右外连接 Right Outer Join On ,无论左边是否匹配到,右边的数据都在 子查询: 将一个 ...

  5. EasyUI DataGrid 获得分页信息

    var b = $('#SBDiv_1_DateGrid').datagrid('options'); console.info(b); 具体需要哪些字段,可以通过火狐debug,然后自己找需要的信息 ...

  6. Redis (非关系型数据库) 数据类型 之 String类型

    Redis 一个内存数据库,通过 Key-Value 键值对的的方式存储数据.由于 Redis 的数据都存储在内存中,所以访问速度非常快,因此 Redis 大量用于缓存系统,存储热点数据,可以极大的提 ...

  7. H.264, MPEG4之间的关系

    百度百科搜索 H.264 H.264是国际标准化组织(ISO)和国际电信联盟(ITU)共同提出的继MPEG4之后的新一代数字视频压缩格式.H.264是ITU-T以H.26x系列为名称命名的视频编解码技 ...

  8. 【Java】生成图形验证码

    本章介绍一个能生成比较好看的图形验证码类 生成验证码工具类 package com.util; import java.awt.Color; import java.awt.Font; import ...

  9. svn log — 显示提交日志信息

    http://www.cnblogs.com/eoiioe/archive/2009/01/06/1370580.html 概要svn log [PATH]svn log URL [PATH...]描 ...

  10. 2018.12.18 bzoj5296: [Cqoi2018]破解D-H协议(bsgs)

    传送门 bsgsbsgsbsgs基础题. 考虑到给的是原根,因此没无解的情况. 于是只需要每次把a,ba,ba,b解出来. 然后可以通过预处理节省一部分时间. 代码: #include<bits ...