Quote:
Originally Posted by dampyr
is the purpose of last code block:
public MyClass(string newname)
{
name = newname;
intval = 0;
}
to define fields which are declared in first block code:
public class MyClass
{
public readonly string name;
private int intval;
or, something else?
|
The member of the class MyClass named MyClass has the same name as the class and thus is a constructor. See page 217 on constructors. From the book: "...you can provider your own, if required, which enables you to initialize ... your objects...
In the sample code you posted, the fields name and intval are initialized in the constructor.