H
HolyCow
I'm in the early stages of learning csharp. I have an example class, and
I'm trying to understand it clearly. I've included comments and questions.
Any clarification would be greatly appreciated.
class Point
{
// This is a constructor because it is named the
// same as the class? I'm also defining 2 parameters that
// can be passed to an instance of this class.
public Point(int x, int y)
{
this.x = x; //setting the value of the member fields
this.y = y; //to the values passed.
}
// Declaring member fields.
// Why do we declare them after they have
// been referenced in the constructor?
// Declaring member fields with the same name as the parameters
// seems odd -- seems like a bad idea?
public int x;
public int y;
}
I'm trying to understand it clearly. I've included comments and questions.
Any clarification would be greatly appreciated.
class Point
{
// This is a constructor because it is named the
// same as the class? I'm also defining 2 parameters that
// can be passed to an instance of this class.
public Point(int x, int y)
{
this.x = x; //setting the value of the member fields
this.y = y; //to the values passed.
}
// Declaring member fields.
// Why do we declare them after they have
// been referenced in the constructor?
// Declaring member fields with the same name as the parameters
// seems odd -- seems like a bad idea?
public int x;
public int y;
}