How to create a colletion of properties in a C# class
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to create a colletion of properties in a C# class

  1. #1
    Join Date
    Jul 2003
    Posts
    2

    How to create a colletion of properties in a C# class

    Hello folks,

    Happy New Year!!!

    I have a class that has couple of properties.

    Can I have a property in that class that can be a collection. Like say the MarketData. can I have a property say "FailedCurves" . It is a string property. But only thing is, this property is an ArrayList or Dictionary object that can have multiple string items in it.

    How can I do that in C#? Am I thinking correct?

    Thanks much

    Code:
    public class MarketData
        {
            #region "Private Data Members"
            private int _countAdvanceCurve;       
            private int _countAdvancesSBCAgencyCurve;
            private int _countAdvancesSBCAAACurve;
            private int _countFhlbsfTreasuryCurve;
            private int _countDNCOCurve;  
            #endregion "Private Data Members"
            #region "Public Data Members"
            public int CountAdvanceCurve
            {
                get { return _countAdvanceCurve; }
                set { _countAdvanceCurve = value; }
            }
    }

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,000

    Re: How to create a colletion of properties in a C# class

    You can surely return an object as a property:

    Code:
    class
    {
        private Dictionary<int, string> privateDict;
    
        public Dictionary DictionaryProperty
        {
            get { return this.privateDict; }
            set { this.privateDict = value; } //Or you can omit the setter, if you like
        }
    }
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center