1.1 Introduction

If you are anything like me, the following is a common scenario: You are writing some code not in the language you traditionally use. Although you know a needed command in your language of choice, the keyword in the language you are using is not even remotely similar, and you can't even think of a word to type in the help file to try to get it. You want to be able to flip through a short book that has your keyword in it, along with the equivalent way of coding it in the new language you are using. This book attempts to fill that need.

This book—as well as my recognition of the need for it—grew out of my own experience. I was teaching courses on VB.NET exclusively. Then one day, I was asked to teach a C# course. It was in front of about 25 C# students that I figured out, the hard way, that knowing VB.NET does not mean you automatically know C# (and I even knew C++).

Microsoft has advertised that the .NET runtime is language agnostic, and that C# and VB.NET are so close that switching between the two is really nothing more than choosing between semicolons and Dims. That is true to a certain extent. However, during that week in front of the firing squad, I discovered that there were a lot of differences between the two, some really obvious, and some more subtle.

The differences, it seemed to me, occur in three main areas: syntax, object-oriented principles, and the Visual Studio .NET IDE. Syntax concerns the statements and language elements; you say tomato, I say toe-mah-toe. Object-oriented differences are more subtle, and concern differences in implementation and feature sets between the two languages. They concern things such as inheritance and method overloading. IDE differences include things like compiler settings, which are attributes you set through the IDE that have different effects depending on what language you use. There is also a fourth area of difference: language features that are present in one language but have no equivalent in the other. These unique language features are also covered in this book.

After my C# class was over, I began writing a book to help me switch between the two languages. I realized that a lot of people were in the same boat, because we find an example in the docs or in a book that does not have the other language's equivalent, or because we are in a job that requires the use of the other language, or because we are curious about what the other language can do, or most commonly because we would like to be able to tell people, "I know both."

Before I begin, some ground rules. Neither language is better than the other. You will not hear me say, "VB is better than C#," or vice versa. I love both languages equally. Also, this book assumes you know one of the two languages, but does not make an assumption about the one you know. The information is presented in a language-neutral point of view so that programmers from each camp can read a section and feel that it is targeted to them.

1.1.1 Conventions Used in This Book

Italic is used for filenames, URLs, and to introduce new terms.

Constant width is used for code and to indicate keywords, parameters, attributes, and other code items within text.

Constant width bold is used to highlight parts of code sections.

figs/vbicon.gifThis icon indicates a Visual Basic .NET code fragment.

figs/csharpicon.gifThis icon indicates a C# code fragment.