Get 20M+ Full-Text Papers For Less Than $1.50/day. Start a 14-Day Trial for You or Your Team.

Learn More →

A Programmer’s Introduction to C# 2.0Classes 101

A Programmer’s Introduction to C# 2.0: Classes 101 CHAPTER 5 ■ ■ ■ 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# you’ll use often, and the later sections describe features you won’t use as often, depending on what kind of code you’re writing. A Simple Class A C# class can be very simple: class VerySimple int 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 speci- fying how accessible it is, it’s private to the VerySimple class and can’t be referenced outside the class. The private modifier could be specified to state this explicitly. The integer simpleValue is a member of the class; there can be many different types of members. In the Main() function, the system creates the instance in heap memory and returns a reference to the instance. A reference is simply a way to refer to an instance. There’s no need to specify when an instance is no longer needed. In the preceding example, as soon as the Main() function completes, the reference to the instance http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png

A Programmer’s Introduction to C# 2.0Classes 101

Editors: Gunnerson, Eric; Wienholt, Nick

Loading next page...
 
/lp/springer-journals/a-programmer-s-introduction-to-c-2-0-classes-101-V5lb66wGa0
Publisher
Apress
Copyright
© Apress 2005
ISBN
978-1-59059-501-5
Pages
31 –37
DOI
10.1007/978-1-4302-0035-2_5
Publisher site
See Chapter on Publisher Site

Abstract

CHAPTER 5 ■ ■ ■ 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# you’ll use often, and the later sections describe features you won’t use as often, depending on what kind of code you’re writing. A Simple Class A C# class can be very simple: class VerySimple int 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 speci- fying how accessible it is, it’s private to the VerySimple class and can’t be referenced outside the class. The private modifier could be specified to state this explicitly. The integer simpleValue is a member of the class; there can be many different types of members. In the Main() function, the system creates the instance in heap memory and returns a reference to the instance. A reference is simply a way to refer to an instance. There’s no need to specify when an instance is no longer needed. In the preceding example, as soon as the Main() function completes, the reference to the instance

Published: Jan 1, 2005

There are no references for this article.