I'm getting an application from my friends to develop. Then in the code I got confusing code like this:
public someNameHere()
{
base..ctor();
}
Well I've never had an application like this. I need an explanation for this
base..ctor();
I've googling and can't find answer that satisfy me. I appreciate for any help you give me.
base (C# Reference) The base keyword is used to access members of the base class from within a derived class: Call a method on the base class that has been overridden by another method. Specify which base-class constructor should be called when creating instances of the derived class.
In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.
In C#, both the base class and the derived class can have their own constructor. The constructor of a base class used to instantiate the objects of the base class and the constructor of the derived class used to instantiate the object of the derived class.
So if in the initialization process of child class there may be the use of parent class members. This is why the constructor of the base class is called first to initialize all the inherited members.
.ctor()
is the internal name used by constructors. It is not used that way in C#, and does not compile. More typically, base..ctor()
is only used by the compiler when doing things like:
public class Foo : Bar {
public Foo(string s) : base(s) {...}
public Foo() {...} // has an implicit :base()
}
The only times I've seen that done differently is when decompiling (via reflector etc) some non-C# IL that does the construction code in a different sequence to how the C# compiler does it, which is therefore not expressable in "pure" C#. In raw IL (and from C++ etc) you can call the base-constructor at any point in the constructor - not just at the start.
Should be the default parameterless constructor of your base class.
Elaborating, .ctor()
is the alias for constructor automatically generated compiling C#. So Writing base..ctor()
is referencing the .ctor()
method in the base class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With