Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Custom Collection Class

Custom Collection Class

Scheduled Pinned Locked Moved C#
help
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SakthiSurya
    wrote on last edited by
    #1

    Hi, I want to create a Custom collection Class Where i can store values by just CollectionObject.Key=Value; Is it Possible to do like this. If not is it possible to create dynamic properties to a class. Please Help me Thanks Sakthi.

    M 1 Reply Last reply
    0
    • S SakthiSurya

      Hi, I want to create a Custom collection Class Where i can store values by just CollectionObject.Key=Value; Is it Possible to do like this. If not is it possible to create dynamic properties to a class. Please Help me Thanks Sakthi.

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, You mean like this?

      	public object Key
      	{
      		get
      		{
      			return this.List\[List.Count-1\];	//Allways returns the last member of the List
      		}
      		set
      		{
      			if(!this.List.Contains(value))
      			{
      				this.List.Add(value);
      			}
      		}
      	}
      

      All the best, MArtin

      S 1 Reply Last reply
      0
      • M Martin 0

        Hello, You mean like this?

        	public object Key
        	{
        		get
        		{
        			return this.List\[List.Count-1\];	//Allways returns the last member of the List
        		}
        		set
        		{
        			if(!this.List.Contains(value))
        			{
        				this.List.Add(value);
        			}
        		}
        	}
        

        All the best, MArtin

        S Offline
        S Offline
        SakthiSurya
        wrote on last edited by
        #3

        Hi Martin, Thanks for your reply. CollectionObject.Key = Value; Key here refers the key to be stored in the collection class for Reference. Forexample Dictionary MyDict=new Dictionary() MyDict[Key] = Value; Instead of using [](Square Braces i just want to use dot(.) Symbol. Regards, Sakthi.

        M T 2 Replies Last reply
        0
        • S SakthiSurya

          Hi Martin, Thanks for your reply. CollectionObject.Key = Value; Key here refers the key to be stored in the collection class for Reference. Forexample Dictionary MyDict=new Dictionary() MyDict[Key] = Value; Instead of using [](Square Braces i just want to use dot(.) Symbol. Regards, Sakthi.

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Apart from, that I don't understand what you mean. Why would you whant to do something like this? :confused:

          1 Reply Last reply
          0
          • S SakthiSurya

            Hi Martin, Thanks for your reply. CollectionObject.Key = Value; Key here refers the key to be stored in the collection class for Reference. Forexample Dictionary MyDict=new Dictionary() MyDict[Key] = Value; Instead of using [](Square Braces i just want to use dot(.) Symbol. Regards, Sakthi.

            T Offline
            T Offline
            Tim Paaschen
            wrote on last edited by
            #5

            This is a really strange idea! All possible keys must be known at compile-time. However, technically this can be achieved by adding a Dictionary member to you custom Collection and provide a property for each possible key that just wraps the indexer of the dictionary.

            Regards, Tim

            M 1 Reply Last reply
            0
            • T Tim Paaschen

              This is a really strange idea! All possible keys must be known at compile-time. However, technically this can be achieved by adding a Dictionary member to you custom Collection and provide a property for each possible key that just wraps the indexer of the dictionary.

              Regards, Tim

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Tim Paaschen wrote:

              This is a really strange idea!

              I do agree!

              Tim Paaschen wrote:

              and provide a property for each possible key

              Think about that again! (He will set a long time infront of his computer, and than one day his heart will stop beating) As we all don't whant him to die infront of the computer writing this "strange" program, we should tell him to search for a better solution! All the best, Martin

              S T 2 Replies Last reply
              0
              • M Martin 0

                Tim Paaschen wrote:

                This is a really strange idea!

                I do agree!

                Tim Paaschen wrote:

                and provide a property for each possible key

                Think about that again! (He will set a long time infront of his computer, and than one day his heart will stop beating) As we all don't whant him to die infront of the computer writing this "strange" program, we should tell him to search for a better solution! All the best, Martin

                S Offline
                S Offline
                SakthiSurya
                wrote on last edited by
                #7

                Hi, Thank you very much for your Suggestion and Concern. Regards, Sakthi.

                1 Reply Last reply
                0
                • M Martin 0

                  Tim Paaschen wrote:

                  This is a really strange idea!

                  I do agree!

                  Tim Paaschen wrote:

                  and provide a property for each possible key

                  Think about that again! (He will set a long time infront of his computer, and than one day his heart will stop beating) As we all don't whant him to die infront of the computer writing this "strange" program, we should tell him to search for a better solution! All the best, Martin

                  T Offline
                  T Offline
                  Tim Paaschen
                  wrote on last edited by
                  #8

                  Martin# wrote:

                  Think about that again! ...

                  I never said that it is a good idea - just that it is technically possible.

                  Regards, Tim

                  M 1 Reply Last reply
                  0
                  • T Tim Paaschen

                    Martin# wrote:

                    Think about that again! ...

                    I never said that it is a good idea - just that it is technically possible.

                    Regards, Tim

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #9

                    Hello (Hallo) Tim,

                    Tim Paaschen wrote:

                    I never said that it is a good idea

                    I know, and my answere was more meant as a joke than a critic on your statement.

                    Tim Paaschen wrote:

                    just that it is technically possible

                    Technically possible, would be a set of keys which he defines during design time. "All possible Keys" is not technically possible! All the best (Noch einen schönen Tag) Martin

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups