Results 1 to 13 of 13

Thread: propertys

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    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?

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    but that way it would appear as class and it appears as property!

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    HAHA thats ok LOL

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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());

  7. #7
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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?

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  10. #10

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah tks worksssssss weee

  11. #11

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    is there a way that the size class is invisible to the rest of the application and only the myObject can be seen?

  12. #12
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Nest the size class within the myObject class and make it private.

  13. #13

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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
  •  



Click Here to Expand Forum to Full Width