Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Accessors

$
0
0

I am trying to understand the reason behind the Engineers @ Microsoft Lab decided to add the get and set attributes. Was it just to simply add a feature or there are actual advantages, 4ex:

// Snip
    class Name {
        private String first_name;
         ....

        public String FirstName {
            get { return first_name;  }
            set { first_name = value; }
        }
                 // VS
       public String getFirstName{ return first_name;  }
       public String setFirstName{ first_name = value; }
       ....
}

does the very same thing. While I can add verification code to the (g/s)etFirstname methods, I cannot add any other code to the (g/s)et attributes. I would really appreciate a bit of help understanding the wisdom behind the (g/s)et attributes.

Thanks in advance


Worry is a misuse of imagination :)


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>