-1

What does ":this(100)" mean in a C# method declaration?

While reading MDSN docs I came across it in line 6 of the following code:

  public class Stack
    {
       readonly int m_Size; 
       int m_StackPointer = 0;
       object[] m_Items; 
       public Stack():this(100)
       {}   
       public Stack(int size)
       {
          m_Size = size;
          m_Items = new object[m_Size];
       }
    }
TokyoDan
  • 196
  • 1
  • 11
  • That's not a regular method, it's a constructor. Besides, programming questions should be asked on [so] as they are off topic here on Super User. See [What topics can I ask about here?](https://superuser.com/help/on-topic) in our help center for more about what topics are allowed here. – user Jul 30 '15 at 08:09

1 Answers1

0
public Stack()

Is the default constructor

public Stack(int size)

Is the parametric constructor

public Stack():this(100)

Means the default constructor will call parametric constructor with parameter size as 100.

Refer to this Construtor for more information

This is used in constructors. It is used to overload the constructors in a C# program. It allows code to be shared between the constructors. Constructor initializers, which use the this-keyword, prove useful in nontrivial classes.

AEonAX
  • 501
  • 12
  • 24