In the esoteric programming language INTERCAL, the colon is called "two-spot" and is used to identify a 32-bit variable—distinct from a spot (.)
A colon is used to give emphasis, present dialogue, introduce lists or text, and clarify composition titles. Emphasis—Capitalize the first word after the colon only if it is a proper noun or the start of a complete sentence.
colon in British English (ˈkəʊlən ) nounWord forms: plural -lons or -la (-lə ) the part of the large intestine between the caecum and the rectum. Collins English Dictionary.
It (along with the this
keyword) is instructing the constructor to call another constructor within the same type before it, itself executes.
Therefore:
public ListNode(object dataValue)
: this(dataValue, null)
{
}
effectively becomes:
public ListNode(object dataValue)
{
data = dataValue;
next = null;
}
Note that you can use base
instead of this
to instruct the constructor to call a constructor in the base class.
It is constructor chaining so the constructor with the subsequent : this
call will chain to the ctor that matches the signature.
So in this instance
public ListNode(object dataValue)
is calling
public ListNode(object dataValue, ListNode nextNode)
with null as the second param via : this(dataValue, null)
it's also worth noting that the ctor called via the colon executes before the ctor that was called to initialize the object.
It means before running the body, run the constructor with object and ListNode parameters.
It calls the other ListNode constructor. You can do a similar thing with the base keyword to call a constructor of a class you're deriving from.
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