C# for Java Programmers

C# is a modern object-oriented programming language (OOPL) just like Java. This means that it upholds the three pillars of object-oriented programming encapsulation, inheritance, and polymorphism. This chapter will review the concepts of objects and classes, which is the heart and soul of any OOPL. Most of this will be very familiar to you, but pay attention there are some differences between the two languages.
This chapter will look at C# classes and objects. Just like Java, all code in C# runs as part of a class that has a group of methods that act upon common data. Each instance of a class is called an object and has its own copy of the data. This is the main difference between an object and a class. C# has introduced new keywords ( ref and out) for declaring and handling method parameters, which will be highlighted in the method parameters section.
The last section of this chapter will discuss how to create and destroy objects. You will learn how to create constructors and destructors for your class. A constructor is the very first method called when you instantiate your object. A destructor is a method you can use to free up unmanaged resources for you object. However, the Common Language Runtime (CLR) provides a garbage collector for cleaning up your objects after they are used, so you don t need to explicitly declare a destructor. Let s now proceed and see how these are all done.
C# and Java both use classes...