...

/

Solution Review: Implement the Complete Student Class

Solution Review: Implement the Complete Student Class

This review provides a detailed analysis to solve the 'Implement the Complete Student Class' challenge.

We'll cover the following...

Solution

Press + to interact
class Student // Student Class
{
// Fields
private string _name;
private string _rollNumber;
// Properties
public string Name
{
set
{
this._name = value;
}
get
{
return this._name;
}
}
public string RollNumber
{
set
{
this._rollNumber = value;
}
get
{
return this._rollNumber;
}
}
}
class Program
{
public static void Main()
{
Student student = new Student();
student.Name = "John";
student.RollNumber = "20";
System.Console.WriteLine(student.Name + " " + student.RollNumber);
// In an Encapsulated implementation the following should return an error
// student._name = "John";
// student._rollNumber = "20";
}
}

Explanation

  • Line 4-5: We have implemented the Student class which has the private fields
...