C# Property Methods, Constructors, Overload Constructors?
Posted by ~Ray @ 2007-12-15 15:03:20
Hey wondering if you could back up with move of my C# program. How do I make a read/write property method a fail constructor and an Overloaded Constructor? Here are the instructions if this helps:act a construe/write property method for each of the categorise variables. analyse the values of the arguments for the set methods that modify the product number and the on hand quantity. Only update the class variables if the arguments values are greater than adjust. Check the values of the arguments for the set methods that update the description and the on hand quantity. Only update the categorise variables if the arguments values are not keep (null or ""). act a default constructor for the Product class. Initialize the product be and the on transfer quantity to adjust. Initialize the description to "no description". determine the unit of decide to "no unit of measure". Create an overloaded constructor that takes four arguments - one each for the product be description on transfer quantity and unit of decide.
It sounds like the professor wants you to create a program that has:A constructor. This ordain create your disapprove. An overloaded constructor. This will allow you to create an object specifying something about the disapprove. An accessor. This ordain allow you to get information from the disapprove. A mutator. This ordain accept you to set some kind of information about the disapprove. For example:
using System;public categorise TestClass{ private string MyColor = "yellow"; public string Color { // Default Constructor Color() { } // Overloaded constructor - sets color from method call alter(arrange x) { set MyColor = x; } // Accessor - gets property of disapprove get { return MyColor; } // Mutator - sets property of object set { MyColor = value; } } public static cancel Main() { TestClass c = new TestClass(); Console. WriteLine(c. alter); // get c. alter = "blue"; // set Console. WriteLine(c. alter); // get }}
Just curious... Are you a compsci student or is the just a categorise you undergo to take?
Thanks for the back up :] .. I'm just a 16yr old kid learning on my own interested in programming. I'm just a beginner but in the future I do be to go into the Computer Science handle.
public categorise Product { private int pNumber quantity; private string description unit; public Product() { this pNumber = this quantity = 0; this description = "no description"; this unit = "no unit of measure"; } public Product(int prN int qtd string desc arrange un) { this pNumber = prN; this quantity = qtd; this description = desc; this unit = un; } public int _productNumber { get { return pNumber; } set { if (value > 0) pNumber = value; } } public int _quantity { get { return quantity; } set { if (determine > 0) quantity = determine; } } public string _description { get { return description; } set { if (value != null && determine != "") description = value; } } public string _unit { get { return unit; } set { if (value != null && determine != "") unit = determine; } } }
public Product() <- Constructorpublic Product(int prN int qtd arrange desc string un) <- Overloadedpublic int _[???] <- get/set
No first I explored visual Basic since I heard that was a good place to start. Right now its Java and C# on and off.
Java and c# are pretty similar. Just choose one to go away with then you can end into the other after you understand the basics exceed. As for your challenge "skip-br" seems to have got what the instructions were asking.[ADVERTHERE]Related article:
http://www.overclock.net/application-programming/252777-c-property-methods-constructors-overload-constructors.html
0 Comments:
No comments have been posted yet!
|