What is the meaning of CTOR?

前端 未结 4 990
心在旅途
心在旅途 2021-01-30 12:08

In a lot of C# files I save regions tags(?) that are named CTOR or ctor. What\'s the meaning of ctor? Why is such a region called ctor?

相关标签:
4条回答
  • 2021-01-30 12:30

    To expand a little more, there are two kinds of constructors: instance initializers (.ctor), type initializers (.cctor). Build the code below, and explore the IL code in ildasm.exe. You will notice that the static field 'b' will be initialized through .cctor() whereas the instance field will be initialized through .ctor()

    internal sealed class CtorExplorer
    {
       protected int a = 0;
       protected static int b = 0;
    }
    
    0 讨论(0)
  • 2021-01-30 12:38

    Usually this region should contains the constructors of the class

    0 讨论(0)
  • 2021-01-30 12:39

    Type "ctor" and press the TAB key twice this will add the default constructor automatically

    0 讨论(0)
  • 2021-01-30 12:45

    It's just shorthand for "constructor" - and it's what the constructor is called in IL, too. For example, open up Reflector and look at a type and you'll see members called .ctor for the various constructors.

    0 讨论(0)
提交回复
热议问题