Results 1 to 4 of 4

Thread: Get and Set Help [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    102

    Resolved Get and Set Help [RESOLVED]

    Lo all,
    having a little trouble with a few get and set properties im trying to do, ther reason why is they are part of an array. I can do this is vb6 pretty easy but dont know how to do it in C#.

    Can someone point me in the right direction, currently I have this which is how it would be done if acAccountNote wasnt an array but unfortunatly it is hehe. Any ideas how to do this with an array??

    VB Code:
    1. private string AccountNote
    2.         {
    3.             get
    4.             {
    5.                 return acAccountNote;
    6.             }
    7.             set
    8.             {
    9.                 acAccountNote = value;
    10.             }
    11.         }
    Last edited by Hack; Feb 23rd, 2006 at 09:09 AM. Reason: Added green "resolved" checkmark

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Get and Set Help

    First of all I am confused. If you are creating a property why would it be private?

    To have the property use array, you will need to declare the property as array
    Code:
    	
    //private member that will hold the data
    private string[] acAccountNote;
    public string[] AccountNote 
    {
    	get
    	{
    		return acAccountNote;
    	}
    	set
    	{
    		acAccountNote = value;
    	}
    }
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Get and Set Help

    You can try

    PHP Code:
    public const int intCount 10;
            private static 
    string[] _strArr = new int[intCount];
            
            public static 
    string [] MYPROPERTY 
            
    {
                
    get { return _strArr; }
                
    set _strArr value; }
            } 
    But it'd be better to use an ArrayList or a similar collection.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    102

    Re: Get and Set Help

    Quote Originally Posted by Shuja Ali
    First of all I am confused. If you are creating a property why would it be private?

    To have the property use array, you will need to declare the property as array
    Code:
    	
    //private member that will hold the data
    private string[] acAccountNote;
    public string[] AccountNote 
    {
    	get
    	{
    		return acAccountNote;
    	}
    	set
    	{
    		acAccountNote = value;
    	}
    }
    oops sorry lol, it is public in my code just I typed it wrong on this hehe. guess i should start copy and pasting Thanks for the help it works now!!

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