constructor syntax

  • Thread starter Thread starter DeveloperX
  • Start date Start date
D

DeveloperX

Hi,

I've been looking at a csv parse I found on CodeProject, and I don't
recognise the syntax used in the constructors. Here's an example:

public CachedCsvReader(TextReader reader, bool hasHeaders)
: this(reader, hasHeaders, DefaultBufferSize)
{
}

Is this basically saying pass through to the constructor that takes
(reader, hasHeaders, DefaultBufferSize) ?

Thanks.
 
DeveloperX said:
I've been looking at a csv parse I found on CodeProject, and I don't
recognise the syntax used in the constructors. Here's an example:

public CachedCsvReader(TextReader reader, bool hasHeaders)
: this(reader, hasHeaders, DefaultBufferSize)
{
}

Is this basically saying pass through to the constructor that takes
(reader, hasHeaders, DefaultBufferSize) ?

Yes.

The class uses 2 constructors. The "main constructor" has 3 parameters:
TextReader, hashHeaders and a BufferSize.

If somebody creates an object _without_ declaring a buffer size he uses:

public CachedCsvReader(TextReader reader, bool hasHeaders)

In this case the "main constructor" is called with using a
DefaultBufferSize.


Regards,
Martin
 
In addition to what the gentleman said above me, this also applies to
derived classes, in the sense if you want to call a base class
constructor from a derived class, you could use the same syntax just
replace this() with base()

Sean
 
DeveloperX said:
I've been looking at a csv parse I found on CodeProject, and I don't
recognise the syntax used in the constructors. Here's an example:

public CachedCsvReader(TextReader reader, bool hasHeaders)
: this(reader, hasHeaders, DefaultBufferSize)
{
}

Is this basically saying pass through to the constructor that takes
(reader, hasHeaders, DefaultBufferSize) ?

Yup. See
http://www.pobox.com/~skeet/csharp/constructors.html for more info.

Jon
 
Back
Top