Maha

Maha

  • NA
  • 0
  • 324.8k

Using "this" Reference

Nov 30 2011 1:43 PM
It is said that using this reference can save memory. Can anyone please explin how "this" can save memory. Following one is a example program.

using System;
public class CreateStudent
{
public static void Main()
{
Student x = new Student();

x.SetId(951);
x.SetName("Ross");
x.SetGPA(3.5);

Console.WriteLine
("The student named {0} has ID # is {1} and a gpa of {2}", x.GetName(), x.GetId(), x.GetGPA());

Console.ReadLine();
}
}
class Student
{
private int id;
private string lastName;
private double gpa;

public int GetId()
{
return id;
}
public void SetId(int id)
{
this.id = id;
}

public string GetName()
{
return lastName;
}
public void SetName(string lastName)
{
this.lastName = lastName;
}

public double GetGPA()
{
return gpa;
}
public void SetGPA(double gpa)
{
this.gpa = gpa;
}
}
//The student named Ross has ID # is 951 and a gpa of 3.5


Answers (6)