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

[356 byte] By [ChrisMentioned] at [2007-12-23]
# 1
Make the Bark property return an object which has Loud and Soft properties.
MattiasSj?gren at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 2

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 name

public enum bark

{
Loud,
Soft
}
private bark _bark;
public bark Bark
{
get { return _bark; }
set { _bark = value; }
}

}


hope this helps

Egyptian at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 3

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

ChrisMentioned at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 4
"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.

rauhanlinnake at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 5
oh, thanks for explaining then
ChrisMentioned at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 6

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...)

rayms at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 7
Try something like this:

public class Dog

{

public class BarkProps

{

public bool Able;

public bool Loud;

}

private BarkProps mBark = new BarkProps();

public BarkProps Bark

{

get { return mBark; }

}

}

...

private void button1_Click(object sender, EventArgs e)

{

Dog dog = new Dog();

dog.Bark.Able = true;

dog.Bark.Loud = true;

}

nobugz at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 8

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

Egyptian at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...