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. Other Discussions
  3. The Weird and The Wonderful
  4. Setters and Getters evil future [modified]

Setters and Getters evil future [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
11 Posts 5 Posters 1 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
    stanislav simunec
    wrote on last edited by
    #1

    User Class part :

    Public Property SetChallengedCardList() As Integer
    Set(ByVal value As Integer)
    _challengedCardList.Add(value)
    End Set
    Get
    Return 0
    End Get
    End Property

    Public Property GetChallengedCardList() As ArrayList
    Set(ByVal value As ArrayList)
    _challengedCardList = Nothing
    End Set
    Get
    Return _challengedCardList
    End Get
    End Property

    and latter usage:

    Dim u As New User()
    u.SetChallengedCardList = 25
    u.SetChallengedCardList = 27
    u.SetChallengedCardList = 31

    ;) :laugh:

    sstanko78

    modified on Thursday, April 16, 2009 6:07 AM

    Z S 2 Replies Last reply
    0
    • S stanislav simunec

      User Class part :

      Public Property SetChallengedCardList() As Integer
      Set(ByVal value As Integer)
      _challengedCardList.Add(value)
      End Set
      Get
      Return 0
      End Get
      End Property

      Public Property GetChallengedCardList() As ArrayList
      Set(ByVal value As ArrayList)
      _challengedCardList = Nothing
      End Set
      Get
      Return _challengedCardList
      End Get
      End Property

      and latter usage:

      Dim u As New User()
      u.SetChallengedCardList = 25
      u.SetChallengedCardList = 27
      u.SetChallengedCardList = 31

      ;) :laugh:

      sstanko78

      modified on Thursday, April 16, 2009 6:07 AM

      Z Offline
      Z Offline
      zvjerka24
      wrote on last edited by
      #2

      :thumbsup: NEMA TE NA DALEKO :laugh: :thumbsup: YOU ARE THE MEN :laugh:

      modified on Thursday, April 16, 2009 9:49 AM

      1 Reply Last reply
      0
      • S stanislav simunec

        User Class part :

        Public Property SetChallengedCardList() As Integer
        Set(ByVal value As Integer)
        _challengedCardList.Add(value)
        End Set
        Get
        Return 0
        End Get
        End Property

        Public Property GetChallengedCardList() As ArrayList
        Set(ByVal value As ArrayList)
        _challengedCardList = Nothing
        End Set
        Get
        Return _challengedCardList
        End Get
        End Property

        and latter usage:

        Dim u As New User()
        u.SetChallengedCardList = 25
        u.SetChallengedCardList = 27
        u.SetChallengedCardList = 31

        ;) :laugh:

        sstanko78

        modified on Thursday, April 16, 2009 6:07 AM

        S Offline
        S Offline
        stanislav simunec
        wrote on last edited by
        #3

        Proper solution would be:

        Private _challengedCardList As ArrayList

        Public Sub AddItemToChallengedCardList(ByVal value As Integer)
            \_challengedCardList.Add(value)
        End Sub
        
        
        Public ReadOnly Property GetChallengedCardList() As ArrayList
            Get
                Return \_challengedCardList
            End Get
        End Property
        

        It was 21.00h in the office, so ....

        sstanko78

        N 1 Reply Last reply
        0
        • S stanislav simunec

          Proper solution would be:

          Private _challengedCardList As ArrayList

          Public Sub AddItemToChallengedCardList(ByVal value As Integer)
              \_challengedCardList.Add(value)
          End Sub
          
          
          Public ReadOnly Property GetChallengedCardList() As ArrayList
              Get
                  Return \_challengedCardList
              End Get
          End Property
          

          It was 21.00h in the office, so ....

          sstanko78

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #4

          sstanko78 wrote:

          Public ReadOnly Property GetChallengedCardList() As ArrayList
          Get
          Return _challengedCardList
          End Get
          End Property

          Isn't that mutable? You shouldn't return the whole array as it could then be changed from /outside/. Then puppy's cry.


          Panic, Chaos, Destruction. My work here is done.

          J 1 Reply Last reply
          0
          • N Nagy Vilmos

            sstanko78 wrote:

            Public ReadOnly Property GetChallengedCardList() As ArrayList
            Get
            Return _challengedCardList
            End Get
            End Property

            Isn't that mutable? You shouldn't return the whole array as it could then be changed from /outside/. Then puppy's cry.


            Panic, Chaos, Destruction. My work here is done.

            J Offline
            J Offline
            Jeroen De Dauw
            wrote on last edited by
            #5

            Hey, I'm used to returning the whole array, and I know that it then can be muted, but dno how to prevent this. Could you give an example of how it should be done? Cheers BN

            My little forums: http://code.bn2vs.com 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

            D 1 Reply Last reply
            0
            • J Jeroen De Dauw

              Hey, I'm used to returning the whole array, and I know that it then can be muted, but dno how to prevent this. Could you give an example of how it should be done? Cheers BN

              My little forums: http://code.bn2vs.com 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              AFAIK you have to clone the array.

              Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

              N 1 Reply Last reply
              0
              • D Dan Neely

                AFAIK you have to clone the array.

                Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                N Offline
                N Offline
                Nagy Vilmos
                wrote on last edited by
                #7

                dan neely wrote:

                AFAIK you have to clone the array.

                No, just wrap it:

                System.Collections.Generic.List<string> mutable = new List<string>();
                System.Collections.ObjectModel.ReadOnlyCollection<string> immutable = mutable.AsReadOnly();


                Panic, Chaos, Destruction. My work here is done.

                D J 2 Replies Last reply
                0
                • N Nagy Vilmos

                  dan neely wrote:

                  AFAIK you have to clone the array.

                  No, just wrap it:

                  System.Collections.Generic.List<string> mutable = new List<string>();
                  System.Collections.ObjectModel.ReadOnlyCollection<string> immutable = mutable.AsReadOnly();


                  Panic, Chaos, Destruction. My work here is done.

                  D Offline
                  D Offline
                  Dan Neely
                  wrote on last edited by
                  #8

                  Does that work with normal arrays as well as List<>'s?

                  Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                  N 1 Reply Last reply
                  0
                  • D Dan Neely

                    Does that work with normal arrays as well as List<>'s?

                    Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                    N Offline
                    N Offline
                    Nagy Vilmos
                    wrote on last edited by
                    #9

                    Do I look like I know! :laugh: I was going to flippently say for usre, but I am unable to find it. In Java the base Collection supports immutable references, too late of evening for me to look, and so that goes through all the Map and Set classes. It seems a sensible approach; just not for M$.


                    Panic, Chaos, Destruction. My work here is done.

                    D 1 Reply Last reply
                    0
                    • N Nagy Vilmos

                      Do I look like I know! :laugh: I was going to flippently say for usre, but I am unable to find it. In Java the base Collection supports immutable references, too late of evening for me to look, and so that goes through all the Map and Set classes. It seems a sensible approach; just not for M$.


                      Panic, Chaos, Destruction. My work here is done.

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #10

                      OK. Until recently I've been doing 1.1 framework stuff :doh: , and was wondering if this was an new feature or something I'd managed to not discover in several years of using the language.

                      Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                      1 Reply Last reply
                      0
                      • N Nagy Vilmos

                        dan neely wrote:

                        AFAIK you have to clone the array.

                        No, just wrap it:

                        System.Collections.Generic.List<string> mutable = new List<string>();
                        System.Collections.ObjectModel.ReadOnlyCollection<string> immutable = mutable.AsReadOnly();


                        Panic, Chaos, Destruction. My work here is done.

                        J Offline
                        J Offline
                        Jeroen De Dauw
                        wrote on last edited by
                        #11

                        Thnx dude, didn't know that :)

                        GSoC 2009 student for SMW! --- My little forums: http://code.bn2vs.com --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

                        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