Let's modify our Worker class to utilize properties instead of the Getxxx/Setxxx methods.
As you can see, we still do our data validation and throw exceptions from inside the set part of the properties. Let's take a look at the MSIL of this application. Load the file with the Ildasm.exe and navigate to the class Worker.
get_Age, get_Department and set_Age and set_Department? Yes, the C# compiler generates those methods as the Getxxx and Setxxx methods. In the next part of this article, we will discuss the MSIL Generated code of C# Properties, static properties, read-only properties and more.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |