provided by: 
Originally published at Internet.com
C# Programming Notes # 104 * Preface * Preview * Discussion and Sample Code * Summary * What's Next * Complete Program Listings * Review Questions * Answers -----------------------------------
Preface
This is the second lesson in a miniseries designed to teach you how to write object-oriented programs using C#. This miniseries will describe and discuss the necessary and significant aspects of object-oriented programming (OOP) using C#.
The first lesson in the miniseries was entitled Learning C# and OOP: Getting Started, Objects and Encapsulation.
Comparisons with Java
The miniseries will also make comparisons between C# and Java with respect to both syntax and OOP concepts. I will emphasize the similarities between these two programming environments, which are likely to dominate the programming world in the foreseeable future. By studying these lessons and learning about OOP using C#, you will also be learning quite a lot about OOP using Java.
Relatively high level
I will provide the information in a high-level format, devoid of any prerequisite requirement to know C# syntax. In those cases where an understanding of C# syntax is required, I will provide the necessary syntax information in the form of sidebars and sample programs.
Therefore, if you have a general understanding of computer programming, you should be able to read and understand the lessons in this miniseries, even if you don't have a background in object-oriented programming, or a background in the C# programming language.
Viewing tip
You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different listings while you are reading about them.
Supplementary material
I recommend that you also study the other lessons in my extensive collection of online programming tutorials. You will find those lessons published at developer.com. However, as of the date of this writing, developer.com doesn't maintain a consolidated index of my tutorial lessons, and sometimes they are difficult to locate there. You will find a consolidated index at www.DickBaldwin.com.
Preview
Concentrate on classes
This lesson will concentrate primarily on a discussion of the C# class, and a coomparison of a C# class with a similar Java class.
A simple C# program will be developed to illustrate the definition and use of two different classes. Taken in combination, these two classes simulate the manufacture and use of the car radio object discussed in the previous lesson.
Instance variables and instance methods
You will see the definition of a C# class named Radio. This class includes one instance variable and two instance methods. (The instance variable is a reference variable that refers to a special kind of object that I call an array object. I will provide a very brief discussion of array objects in this lesson. I will have more to say about array objects in a future lesson.)
Creating a new object
You will learn how to write code to create a new Radio object by applying the new operator to the constructor for a C# class named Radio. You will also learn how to save that object's reference in a reference variable of type Radio.
Defining methods
You will learn how to write C# code that is used to simulate the association of a radio button with a particular radio station.
You will learn how to write C# code that is used to simulate the pressing of a radio button to play the radio station associated with that button.
The Main method
You will see the definition of a C# class named Radio01. This class consists simply of the Main method. You will learn that the Main method of a C# program is executed by the C# Common Language Runtime (CLR) when the program is run. Thus, the Main method is the driver for the entire program.
Comparison with Java code
In addition, you will learn how to write Java code to perform the tasks described above. You will learn about the similarities and differences between the C# code and the Java code. You will learn that at this level, there is very little difference between C# and Java.
Static variables
I will provide a short discussion of static variables, which are not used in this program. I will explain that the use of static variables can often lead to undesirable side effects.
General class-definition syntax
Finally, I will provide a very brief discussion of the general syntax of a simple class definition in C#.
Discussion and Sample Code
What is a class?
A class is a plan from which many objects can be created. In an earlier lesson, I likened the class definition to the plans from which millions of nearly identical car radios can be manufactured.
A simple C# program
In this lesson, I will provide and discuss a simple C# program. This will help to get you started on the right foot. I will also compare this simple C# program with a Java program designed to accomplish the same purpose. This will illustrate the similarity of these two programming environments.
The complete C# program is shown in Listing 11, near the end of the lesson. This program simulates the manufacture and use of a car radio. The complete Java program is shown in Listing 12 near the end of the lesson.
Explain in fragments
In order to help you to focus specifically on important sections of code, I will explain the behavior of this program in fragments.
Top-level classes
This program contains two top-level class
Author: Richard G. Baldwin
Read article at Internet.com site