What is the meaning of CTOR?

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

4 Answers

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.

10

Usually this region should contains the constructors of the class

1

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;
}

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

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like