Hey, I have no idea why this code isn't working. All I'm trying to do is make a 'getter' and 'setter' method inside C# (using Visual Web Developer 2005 Express Edition).
Here is the Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class Hamster
{
private string m_helloVar;
//Default constructor
public Hamster()
{
this.m_helloVar = "Hi again.";
}
//constructor
public Hamster(string helloVar)
{
this.m_helloVar = helloVar;
}
//Getters and Setters
public string helloVar
{
get
{
return this.m_helloVar;
}
set
{
this.m_helloVar = value;
}
}
}
public partial class _Default : System.Web.UI.Page
{
Hamster Joe = new Hamster();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = Joe.helloVar;
}
protected void Button2_Click(object sender, EventArgs e)
{
Joe.helloVar = TextBox2.Text;
}
}
As you can see I created the "Hamster" class. Inside it is the variable "m_helloVar". Then I go on to define some contructor methods and then the 'getter' and 'setter' methods. But when I implement the getter and setter methods in the code using some buttons, the variable remains unchanged.
I've tried several different ways and I can't seem to come up with a solution. I hope someone here can figure it out.
Thanks.
www.fishbrosentertainment.com