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. about array and property

about array and property

Scheduled Pinned Locked Moved C#
data-structuresregex
10 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.
  • C Offline
    C Offline
    clj19870503
    wrote on last edited by
    #1

    if i use this code, do it have no sense private int[] testProtery = new int[3]; public int[] TestProtery { get { return this.testProtery; } set { this.testProtery = value; } } i want to uee the property to match the private filed of testProtery, i feel this code don't work. please let me understand. thank you

    M X C 3 Replies Last reply
    0
    • C clj19870503

      if i use this code, do it have no sense private int[] testProtery = new int[3]; public int[] TestProtery { get { return this.testProtery; } set { this.testProtery = value; } } i want to uee the property to match the private filed of testProtery, i feel this code don't work. please let me understand. thank you

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      clj19870503 wrote:

      i feel this code don't work

      why would it not work?

      If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting

      1 Reply Last reply
      0
      • C clj19870503

        if i use this code, do it have no sense private int[] testProtery = new int[3]; public int[] TestProtery { get { return this.testProtery; } set { this.testProtery = value; } } i want to uee the property to match the private filed of testProtery, i feel this code don't work. please let me understand. thank you

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #3

        sure, it'll work.

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        1 Reply Last reply
        0
        • C clj19870503

          if i use this code, do it have no sense private int[] testProtery = new int[3]; public int[] TestProtery { get { return this.testProtery; } set { this.testProtery = value; } } i want to uee the property to match the private filed of testProtery, i feel this code don't work. please let me understand. thank you

          C Offline
          C Offline
          clj19870503
          wrote on last edited by
          #4

          for exampel , do i use this : this.testProtery[0].TestProtery; i don't understand, thank you .

          M C 2 Replies Last reply
          0
          • C clj19870503

            for exampel , do i use this : this.testProtery[0].TestProtery; i don't understand, thank you .

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            well it depends what you want to access? if you have, for example, an array of string for different data you might do something like the following.

            private string[] stringData = new string[2];

            public string Name{
            get{return stringData[0];
            set{stringData[0] = value;
            }

            public string JobTitle{
            get{return stringData[1];
            set{stringData[1] = value;
            }

            thou in this instance you would prob want to have two different string instances for the data

            Life goes very fast. Tomorrow, today is already yesterday.

            1 Reply Last reply
            0
            • C clj19870503

              for exampel , do i use this : this.testProtery[0].TestProtery; i don't understand, thank you .

              C Offline
              C Offline
              Curtis Schlak
              wrote on last edited by
              #6

              Ok, stay with me on this. Let's say that you have

              public class TestClass
              {
              private int[] _field;
              }

              Now, in a method of TestClass, you would have the following to reference the value of _field.

              public class TestClass
              {
              public void DoSomethingWithTheField()
              {
              if(null == _field)
              {
              this._field = new int[3]; // or just _field = new int[3];
              }
              }
              private int[] _field;
              }

              Now, let's add a property that allows getting and setting on _field.

              public class TestClass
              {
              public int[] Property
              {
              get { return _field; }
              set { _field = value; }
              }

              public void DoSomethingWithTheField()
              {
              if(null == _field)
              {
              this._field = new int[3]; // or just _field = new int[3];
              }
              }
              private int[] _field;
              }

              Now, you can have a method that will do something like this.

              public class TestClass
              {
              public void DoSomethingWithTheProperty(int secondValue)
              {
              this.Property[1] = secondValue; // or Property[1] = secondValue;
              }

              public int[] Property
              {
              get { return _field; }
              set { _field = value; }
              }

              public void DoSomethingWithTheField()
              {
              if(null == _field)
              {
              this._field = new int[3]; // or just _field = new int[3];
              }
              }
              private int[] _field;
              }

              You see? When you expose a property as an array of integers, you can just use it like an array of integers.

              "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

              C 1 Reply Last reply
              0
              • C Curtis Schlak

                Ok, stay with me on this. Let's say that you have

                public class TestClass
                {
                private int[] _field;
                }

                Now, in a method of TestClass, you would have the following to reference the value of _field.

                public class TestClass
                {
                public void DoSomethingWithTheField()
                {
                if(null == _field)
                {
                this._field = new int[3]; // or just _field = new int[3];
                }
                }
                private int[] _field;
                }

                Now, let's add a property that allows getting and setting on _field.

                public class TestClass
                {
                public int[] Property
                {
                get { return _field; }
                set { _field = value; }
                }

                public void DoSomethingWithTheField()
                {
                if(null == _field)
                {
                this._field = new int[3]; // or just _field = new int[3];
                }
                }
                private int[] _field;
                }

                Now, you can have a method that will do something like this.

                public class TestClass
                {
                public void DoSomethingWithTheProperty(int secondValue)
                {
                this.Property[1] = secondValue; // or Property[1] = secondValue;
                }

                public int[] Property
                {
                get { return _field; }
                set { _field = value; }
                }

                public void DoSomethingWithTheField()
                {
                if(null == _field)
                {
                this._field = new int[3]; // or just _field = new int[3];
                }
                }
                private int[] _field;
                }

                You see? When you expose a property as an array of integers, you can just use it like an array of integers.

                "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                C Offline
                C Offline
                Cybernate
                wrote on last edited by
                #7

                I am not getting your question. The above post is rather a statement. Can you be a little more specific?

                Regards, Chandra V

                C 1 Reply Last reply
                0
                • C Cybernate

                  I am not getting your question. The above post is rather a statement. Can you be a little more specific?

                  Regards, Chandra V

                  C Offline
                  C Offline
                  Curtis Schlak
                  wrote on last edited by
                  #8

                  I have no question. I posted a statement. I walked through the creation of a class with a field of type "integer array," a property that exposed it, and then methods that consume each. It answers the original poster's "how do I access this" question.

                  "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                  C 1 Reply Last reply
                  0
                  • C Curtis Schlak

                    I have no question. I posted a statement. I walked through the creation of a class with a field of type "integer array," a property that exposed it, and then methods that consume each. It answers the original poster's "how do I access this" question.

                    "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                    C Offline
                    C Offline
                    Cybernate
                    wrote on last edited by
                    #9

                    Thanks...

                    Regards, Cybernate

                    C 1 Reply Last reply
                    0
                    • C Cybernate

                      Thanks...

                      Regards, Cybernate

                      C Offline
                      C Offline
                      Curtis Schlak
                      wrote on last edited by
                      #10

                      You're welcome.

                      "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                      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