Hi guys I need some help. I'm completely suck on how to do this with Inheritance.
The aim is to change the value of 'Name' property inherited by the Parent Class (Clothing) of a shirt object.
When a button is clicked withing my C# Web Form by calling the Shirt's method of "ReNameShirt()" to change the name and then display the new 'name'.
My teacher hinted me by saying to use a subroutine. Still lost.
Can you help me out? Much Appreciated.
Clothing Class
using System;
//THE PARENT CLASS 'Clothing'
public class Clothing
{
public string _name;
public string _size;
public string name {get; set;}
public string size {get; set;}
}
//SUBCLASS OF 'Trousers'
public class Trousers : Clothing
{
public string LegLength { get; set; }
public Trousers()
{
LegLength = "91";
}
}
public class Shirt : Clothing
{
public string ReNameShirt()
{
Shirt Po = new Shirt();
Po.name = "blue shirt";
return ReNameShirt();
}
within the Inheritance.aspx.cs file:
protected void Button2_Click(object sender, System.EventArgs e)
{
Shirt myShirt = new Shirt();
myShirt.name = "red polo";
myShirt.size = "85";
Label2.Text = "<b>Name:</b> " + myShirt.name + " <b>Size</b> " + myShirt.size;
myShirt.ReNameShirt();
Label3.Text = myShirt.size;
}
}