C# for Java Programmers

As we have seen, the fundamental building blocks of C# are very similar if not identical to their Java counterparts. Strings in both languages are immutable, but a nonimmutable version of the class is also provided. Flow control is identical, with the lack of fall-through in switch statements being the exception. Arrays are the same as in Java, except for the introduction of two ways of declaring multidimensional arrays, as opposed to one in Java. The foreach statement is a handy new construct brought in from Visual Basic, which makes iterating through collections and arrays simple and natural. Indexers are another new concept not found in Java. They permit you to treat your classes as if they were arrays. The C# collection classes share many of the capabilities of the Java collection classes, and as in Java you can make your own classes into collection classes by implementing an interface. Exception handling is also the same as in Java, except for the lack of the throws keyword. Since C# does not require that you catch exceptions, the throws keyword was not implemented. We also discussed how to make a custom exception class using an interface.