C # Inheritance and the keyword "this"

I am working on some code that was previously written by another developer, and I came across a block of code below:

/// <summary>
/// Default Constructor.
/// </summary>
public Body(Revision parent)
{
  mContainer = parent;
  mSections = new ArrayList();
  mSummary = new ArrayList();
}

/// <summary>
/// Constructs a Body from specified ParseElement.
/// </summary>
/// <param name="parent">Revision container.</param>
/// <param name="elem">Source ParseElement.</param>
public Body(Revision parent, ParseElement elem) : this(parent)
{more constructing stuff}

From what I understand, it is that the overloaded constructor will also call the default constructor with the version I'm sending, as a result of which the initialized ArrayLists will be accessible from the overloaded constructor. Is that right, or am I completely confused?

+3
source share
2 answers

Yes, it's right. However, to correct your terminology:

  • There is no default constructor, except perhaps a constructor without parameters, which does not seem to exist in this class.
  • . .
+12

, . this ,

, .

+3

Source: https://habr.com/ru/post/1775727/


All Articles