Using Properties and sub-properties?
Hello,
i made a property which is not hard to make,
at the moment i have:
Dog.Bark;
But now i want another properties IN bark, like:
Dog.Bark.Loud;
Dog.Bark.Soft;
i know it is possible, because the standard Coordinates, contains X,Y those are sub-properties to.
I hope someone can help me, |
Very much thanks,
Chris
hi,
you can use enum to select from its options,
the cooridantes is something else , its a class which contains 2 properties and those properties you can change its values, but in your case really loud or soft doesn't change its values so you can use enum better
| | class Program{
static void Main(string[] args) { Dog d = new Dog(); d.Bark = Dog.bark.Loud; Console.WriteLine(d.Bark); Dog c = new Dog(); c.Bark = Dog.bark.Soft; Console.WriteLine(c.Bark); } } class Dog{
//i created this enum as part of the dog class but you can declare it outside// of the class, then you can pick a value without refereing to the class namepublic enum bark{ Loud, Soft }
private bark _bark; public bark Bark { get { return _bark; } set { _bark = value; } }} |
hope this helps
Thank you guys,
the last example is not what i meant, but i needed that 2, so thank you for that to :P
But what i actually meant is this:
Dog Test = new Dog();
Test.Dog = "Lucky";
Test.Dog.Bark = true;
Test.Dog.Bark.Loud = true;
Its just more properties in one.
@the other post
Can you please give an example with, return an object properties?
Thank you guys very much for the reply's
Chris
"
Test.Dog.Bark = true;
Test.Dog.Bark.Loud = true;"
and
"
i know it is possible, because the standard Coordinates, contains X,Y those are sub-properties to."Its NOT possible to have a boolean property that has another boolean "sub-property"! Your property needs to be that kind of a type, that has properties it self. For example the Location property of the control class is a Point, that itself has an integer properties X and Y. So the types can have properties. No such thing as sub-properties exist.
Is it a question that you want to write something like 'describeMyDogByName(name, bark, size,colour,age)'? You can use 'out' to pass arguments by reference, which can sometimes simplify things (or complicate them...)
hi,
yes as what what nobugz said you can have a property refer to class, but you can't have bool inside pool, something like the coordinates that you talked about for example
form.Location= new point (x,y) or
form.Location.X = value
form.Location.Y = value
this is a property as a complex type
if you need a property for selections you can use Enum
hope this helps