how do i make something like a Size property? when u put this.Size. then u'll get another property for width and height...how do i do that?
Printable View
how do i make something like a Size property? when u put this.Size. then u'll get another property for width and height...how do i do that?
make a object like
now make a blah object, and set the size properities :)Code:
public class Blah
{
public Blah();
public size Size() = new size();
}
public class size
{
public size();
public int width;
public int height;
}
u can do this with structs, classes and otehr different ways..
the code might not work.. but u get the idea
but that way it would appear as class and it appears as property!
instead of int height, widht, as member variables
make them properities
and when u modify blah object, the blah object modifies class size properties..
i guess u would need to have properties in both to do this
if i am not making any sense jsut tell me to shut up cus its 8 in the morning and i havent gotten any sleep so i might be taking out of my arse :)
HAHA thats ok LOL
here u go a workign copy (dont ask me how i created this at 8 in the morning..) but it works
CALLCode:using System;
namespace CSharptDummy
{
/// <summary>
/// Summary description for myObject.
/// </summary>
public class myObject
{
public myObject()
{
//
// TODO: Add constructor logic here
//
}
public size Size = new size();
public int width
{
get
{
return Size.width;
}
set
{
Size.width = value;
}
}
public int height
{
get
{
return Size.height;
}
set
{
Size.height = value;
}
}
}
public class size
{
public size()
{
}
private int m_width = 0;
private int m_height = 0;
public int width
{
get
{
return m_width;
}
set
{
m_width = value;
}
}
public int height
{
get
{
return m_height;
}
set
{
m_height = value;
}
}
}
}
Code:myObject obj = new myObject();
obj.Size.height = 2;
MessageBox.Show(obj.Size.height.ToString());
to improve this little more..
u can do something cooler and make the properties of myObject to be an size object instead of an int..
the functionality u can add this to or change it aorund is limiteless.. go crazy with it but the basic idea is there i think
hmm..worked ok but the problem is that it shows it as a cyan box...any way that it appears as a property field like some propertys with things inside in .NET do?
Try this. I changed a few things.
PHP Code:using System;
namespace TestCSharp
{
/// <summary>
/// Summary description for myObject.
/// </summary>
public class myObject
{
private size _Size;
public myObject()
{
//
// TODO: Add constructor logic here
//
_Size = new size();
}
public size Size
{
get
{
return this._Size;
}
set
{
this._Size = value;
}
}
}
public class size
{
public size()
{
}
private int m_width = 0;
private int m_height = 0;
public int width
{
get
{
return m_width;
}
set
{
m_width = value;
}
}
public int height
{
get
{
return m_height;
}
set
{
m_height = value;
}
}
}
}
ah tks worksssssss weee
is there a way that the size class is invisible to the rest of the application and only the myObject can be seen?
Nest the size class within the myObject class and make it private.
it gives a gay error:
C:\Documents and Settings\JBRANCO\My Documents\Visual Studio Projects\ConsoleApplication6\Class1.cs(48): Inconsistent accessibility: property type 'ConsoleApplication6.myObject.size' is less accessible than property 'ConsoleApplication6.myObject.Size'