Code:public Form1() { InitializeComponent(); Flower flower1 = new Flower(1, 1, 1, 1, "Daisy"); MessageBox.Show("flower1: \n\n FlowerType=" + flower1.FlowerType); // This is SETTING the value (really, re-setting). flower1.FlowerType="Sunflower"; // The reference to FlowerType below is just GETTING its value. MessageBox.Show("flower1: \n\n FlowerType=" + flower1.FlowerType); Flower flower32=new Flower(4,3,2,1,"Violet") // Just use the MessageBox code above, and you can substitute for flower32. } public class Flower { public Flower(double slength, double swidth, double plength, double pwidth, string ftype) // You could name the above parameters whatever you want, but just know that they are to correspond with your properties in the proper order. { // Here, you are saying that THIS NEW FLOWER has the values that you passed in the parameters above. this.SepalLength = slength; this.SepalWidth = swidth; this.PedalLength = plength; this.PedalWidth = pwidth; this.FlowerType = ftype; } // Now you have to have set and get methods for each. // You can set the property with SET. // You can get the value assigned to a property with GET. // A GET is where you just want the value, as in double number1=flower1.slength (you are getting the slength and assigning it to number) // A SET is where you assign the value, as in flower1.slength=2.34 // Note: You should name your properties better, like below. // This way, you reference by something not so ambiguous, like flower1.FlowerType public double SepalLength { get; set; } public double SepalWidth { get; set; } public double PedalLength { get; set; } public double PedalWidth { get; set; } public string FlowerType { get; set; } }




Reply With Quote