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. HELP pls!!!!

HELP pls!!!!

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
7 Posts 5 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.
  • G Offline
    G Offline
    Gregg Holter
    wrote on last edited by
    #1

    I would like to create a class that could be used to return values. I stored those values in a property so at times I will just retrieve it. My class looks like this: Class1 { private string _name; public Class1(){} public string Name { get { return _name; } set { _name = value; } } } My problem now, lies here: I would like to call those property in a way that "name" variable is an array-like? Meaning if i will use this class, I could have code like this: Class1 c1 = new Class1(); string name1 = c1.Name[0]; string name2 = c1.Name[1]; ... ... ... Could anyone tell me if it's possible to have a property which is array-like? If yes, how is it done? Thank you very much!!!:):):)

    Y D S 3 Replies Last reply
    0
    • G Gregg Holter

      I would like to create a class that could be used to return values. I stored those values in a property so at times I will just retrieve it. My class looks like this: Class1 { private string _name; public Class1(){} public string Name { get { return _name; } set { _name = value; } } } My problem now, lies here: I would like to call those property in a way that "name" variable is an array-like? Meaning if i will use this class, I could have code like this: Class1 c1 = new Class1(); string name1 = c1.Name[0]; string name2 = c1.Name[1]; ... ... ... Could anyone tell me if it's possible to have a property which is array-like? If yes, how is it done? Thank you very much!!!:):):)

      Y Offline
      Y Offline
      Yulianto
      wrote on last edited by
      #2

      clasClass1 { private string _name; //declare the string in array. public Class1(){} public string[] Name { get { return _name; } set { _name = value; } } } Hope this helps, I`m not sure how it`s done. Tell me if it works


      Work hard and a bit of luck is the key to success.

      You don`t need to be genius, to be rich.

      R 1 Reply Last reply
      0
      • Y Yulianto

        clasClass1 { private string _name; //declare the string in array. public Class1(){} public string[] Name { get { return _name; } set { _name = value; } } } Hope this helps, I`m not sure how it`s done. Tell me if it works


        Work hard and a bit of luck is the key to success.

        You don`t need to be genius, to be rich.

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        A slight error in one line. It should look like: private string[] _name;

        1 Reply Last reply
        0
        • G Gregg Holter

          I would like to create a class that could be used to return values. I stored those values in a property so at times I will just retrieve it. My class looks like this: Class1 { private string _name; public Class1(){} public string Name { get { return _name; } set { _name = value; } } } My problem now, lies here: I would like to call those property in a way that "name" variable is an array-like? Meaning if i will use this class, I could have code like this: Class1 c1 = new Class1(); string name1 = c1.Name[0]; string name2 = c1.Name[1]; ... ... ... Could anyone tell me if it's possible to have a property which is array-like? If yes, how is it done? Thank you very much!!!:):):)

          D Offline
          D Offline
          Daniele Mancini
          wrote on last edited by
          #4

          Maybe use an ArrayList (from namespace System.Collections) intead of strings... using System.Collections Class1 { private ArrayList _name=new ArrayList(); public Class1(){} public string Name { get { return _name; } set { _name=value; } } } in this way this code Class1 myClass=new Class1(); Console.WriteLine(myClass.Name[0].ToString()); will write on screen the first object stored converted to string... In this way you can store different types of data (or objects), since ArrayList class is supposed to store "object" objects :P Obviusly you need to know what kind of data you are going to retrieve from the ArrayList... ^^

          G 1 Reply Last reply
          0
          • G Gregg Holter

            I would like to create a class that could be used to return values. I stored those values in a property so at times I will just retrieve it. My class looks like this: Class1 { private string _name; public Class1(){} public string Name { get { return _name; } set { _name = value; } } } My problem now, lies here: I would like to call those property in a way that "name" variable is an array-like? Meaning if i will use this class, I could have code like this: Class1 c1 = new Class1(); string name1 = c1.Name[0]; string name2 = c1.Name[1]; ... ... ... Could anyone tell me if it's possible to have a property which is array-like? If yes, how is it done? Thank you very much!!!:):):)

            S Offline
            S Offline
            S Senthil Kumar
            wrote on last edited by
            #5

            Why don't you try property indexers. For eg, class Class1 { StringArrayClass cs; public StringArrayClass Name { return cs; } class StringArrayClass { public string this[int index] { return array[index]; } }

            G 1 Reply Last reply
            0
            • D Daniele Mancini

              Maybe use an ArrayList (from namespace System.Collections) intead of strings... using System.Collections Class1 { private ArrayList _name=new ArrayList(); public Class1(){} public string Name { get { return _name; } set { _name=value; } } } in this way this code Class1 myClass=new Class1(); Console.WriteLine(myClass.Name[0].ToString()); will write on screen the first object stored converted to string... In this way you can store different types of data (or objects), since ArrayList class is supposed to store "object" objects :P Obviusly you need to know what kind of data you are going to retrieve from the ArrayList... ^^

              G Offline
              G Offline
              Gregg Holter
              wrote on last edited by
              #6

              that didn't work, i've tried it... thanks anyway :)

              1 Reply Last reply
              0
              • S S Senthil Kumar

                Why don't you try property indexers. For eg, class Class1 { StringArrayClass cs; public StringArrayClass Name { return cs; } class StringArrayClass { public string this[int index] { return array[index]; } }

                G Offline
                G Offline
                Gregg Holter
                wrote on last edited by
                #7

                Yes! that's exactly how i did it.. I look on a couple of samples in msdn.. thanks!!! :)

                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