Creating Objects with the new Operator
We already know a couple of ways to create instances of types: the use of literals and default value expressions. And because expressions evaluate to produce something of a certain type, you can use them in all places where objects are expected.
However, so far we’ve yet to discuss one of the most common ways of creating object instances: the use of constructors. Constructors are nothing but regular methods that are defined on a type but are known to serve a special goal: They return an instance of the containing type. Every type can have different constructors that take in different arguments, as a matter of friendliness toward the consumer of the type. This is facilitated by means of method overloading ...
Get C# 5.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.