C# for Java Programmers

Chapter 7: Other C# Features

Introduction

At this point you have learned most of the basic tools for object-oriented programming. This chapter will complete the tool set by introducing the rest of the new C# features that are not found in Java. Many of the concepts in this chapter will be familiar to those who also know C++, but pure Java developers will be unfamiliar with most of these.

This chapter begins by discussing some syntactic sugar that C# provides. We will discuss properties as they apply to the C# language. Properties provide data encapsulation, but allow direct access to member fields. You will then learn about enumerations, a distinct value type consisting of a set of named constants. Next, the chapter will discuss support for boxing and unboxing of data types. This is a convenient way to move from primitives to objects and back. Operator overloading is a powerful new addition to C# that allows users to define how operators behave with objects. In a similar vein, C# also supports user-defined conversions, known as casting to Java programmers. Finally, you will learn about the struct, which is a lightweight user-defined alternative to a class.

Properties

Properties are an interesting addition to C# that allow the benefits of encapsulation while also allowing direct access to a field. In Java, set and get methods are the only way to provide encapsulation of data. C# allows this through the use of properties, which have get and set methods that are invisible to the...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Programming Languages
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.