Page 87      All Pages  All Books
60          Chapter 2 • Introducing C# Programming
The set accessor assigns a value to the member variable m_SSN. The value keyword contains the value of the right side of the equal sign when invoking the set property. The data type of value will be the type in the declaration of the property. In this case, it is a string.
One thing to note about the set accessor is that it can do more than just set the value of a data member. For instance, you could add code to validate the value and not do the assignment if validation fails.
Note
Throughout the samples in this chapter, you will see a lot of string oper­ations that use the overloaded concatenation operators such as “+” and “+=” as in the following code:
string stringl = "a" + "b" + "c"; stringl += "e" + "f";
In C#, strings are immutable, which means they cannot be changed once they have a value assigned to them. In the previous example, each time the string is modified, a new copy of the string is created. This can lead to performance problems in code that does a large amount of string operations. The .NET Framework supplies the System.Text.StringBuilder class, which allows you to create and manipu­late a string using a single buffer in memory for cases where you do a lot of string processing.
Accessing Lists with Indexers
The need to create and manipulate lists is a common programming task. Let’s extend our employee example from the last section. Let’s say you need to display a list of employees. The most logical thing to do would be to create a new Employees class, which contains all of the individual Employee instances. You would then iterate through all of the employees displaying each one until there are no further employees. One way to solve this would be to create a property that returns the number of employees and a method that returns a given employee given its position in the list, such as the following:
for ( i = 0; i < employees.Length; i++ ) {

Page 87      All Pages  All Books