CHAPTER 3

image

Classes 101

Classes are the heart of any application in an object-oriented language. This chapter is broken into several sections. The first section describes the parts of C# that will be used often, and the later sections describe things that won’t be used as often, depending on what kind of code is being written.

A Simple Class

A C# class can be very simple:

class VerySimple{    int m_simpleValue = 0;}class Test{    public static void Main()    {       VerySimple vs = new VerySimple();    }}

This class is a container for a single integer. Because the integer is declared without specifying how accessible it is, it’s private to the ...

Get A Programmer's Guide to C# 5.0, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.