|
-
Nov 12th, 2002, 07:37 AM
#1
Thread Starter
yay gay
propertys
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?
-
Nov 12th, 2002, 07:48 AM
#2
Frenzied Member
make a object like
Code:
public class Blah
{
public Blah();
public size Size() = new size();
}
public class size
{
public size();
public int width;
public int height;
}
now make a blah object, and set the size properities 
u can do this with structs, classes and otehr different ways..
the code might not work.. but u get the idea
-
Nov 12th, 2002, 07:50 AM
#3
Thread Starter
yay gay
but that way it would appear as class and it appears as property!
-
Nov 12th, 2002, 07:54 AM
#4
Frenzied Member
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
-
Nov 12th, 2002, 07:54 AM
#5
Thread Starter
yay gay
-
Nov 12th, 2002, 08:03 AM
#6
Frenzied Member
here u go a workign copy (dont ask me how i created this at 8 in the morning..) but it works
Code:
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;
}
}
}
}
CALL
Code:
myObject obj = new myObject();
obj.Size.height = 2;
MessageBox.Show(obj.Size.height.ToString());
Last edited by kovan; Nov 12th, 2002 at 08:11 AM.
-
Nov 12th, 2002, 08:08 AM
#7
Frenzied Member
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
-
Nov 14th, 2002, 06:09 PM
#8
Thread Starter
yay gay
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?
-
Nov 14th, 2002, 10:02 PM
#9
Frenzied Member
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;
}
}
}
}
Dont gain the world and lose your soul
-
Nov 15th, 2002, 08:12 AM
#10
Thread Starter
yay gay
-
Nov 15th, 2002, 08:31 AM
#11
Thread Starter
yay gay
is there a way that the size class is invisible to the rest of the application and only the myObject can be seen?
-
Nov 15th, 2002, 08:47 AM
#12
PowerPoster
Nest the size class within the myObject class and make it private.
-
Nov 15th, 2002, 09:38 AM
#13
Thread Starter
yay gay
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'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|