C# for Java Programmers

The following Frequently Asked Questions, answered by the authors of this book, are designed to both measure your understanding of the concepts presented in this chapter and to assist you with real-life implementation of these concepts. To have your questions about this chapter answered by the author, browse to www.syngress.com/solutions and click on the Ask the Author form.
| 1. | In Java, I used the Stringbuffer class for strings that were not immutable. Does C# offer a similar class? |
|
| 2. | Why do my fall-through cases not fall through in my switch statement? |
|
| 3. | In Java, we would put a throws specifier on a class if it threw an exception. Is this required in C#? |
|
| 4. | When should I make my class a collection, and when should I use indexers? |
|
Answers
| 1. | Yes, C# offers the StringBuilder class. This class is the counterpart to the Stringbuffer class in Java, and has similar methods. |
| 2. | C# does not support implicit fall-through. You must use the goto command to switch to another case. |
| 3. | No, C# does not support the throws specifier. |
| 4. | If your class can be considered logically, or might be used by someone else as an array, then you might want to use indexers. If you wish to support the foreach iterator, you must make your class a collection. |