Home > Articles > Programming > C#

Understanding Objects and Collections in Visual C# 2005

  • Print
  • + Share This
  • 💬 Discuss
In this hour, you're going to start learning about an important programming concept, namely objects. The more you work with Visual C#, the more you'll hear about objects. Visual C# 2005 is a true object-oriented language. This hour isn't going to discuss object-oriented programming in any detail—object-oriented programming is a complex subject and well beyond the scope of this book. Instead, you'll learn about objects in a more general sense.

What You'll Learn in This Hour:

  • Understanding objects
  • Getting and setting properties
  • Triggering methods
  • Understanding method dynamism
  • Writing object-based code
  • Understanding collections
  • Using the Object Browser

In Hour 1, "Jumping In with Both Feet: A Visual C# 2005 Programming Tour," you were introduced to programming in Visual C# by building a Picture Viewer project. You then spent Hour 2, "Navigating Visual C# 2005," digging into the integrated development environment (IDE) and learning skills critical to your success with Visual C#. In this hour, you're going to start learning about an important programming concept, namely objects.

The term object as it relates to programming might have been new to you prior to this book. The more you work with Visual C#, the more you'll hear about objects. Visual C# 2005 is a true object-oriented language. This hour isn't going to discuss object-oriented programming in any detail—object-oriented programming is a complex subject and well beyond the scope of this book. Instead, you'll learn about objects in a more general sense.

Everything you use in Visual C# is an object, so understanding this material is critical to your success with Visual C#. For example, forms are objects, as are the controls you place on a form; pretty much every element of a Visual C# project is an object and belongs to a collection of objects. All objects have attributes (called properties), most have methods, and many have events. Whether creating simple applications or building large-scale enterprise solutions, you must understand what an object is and how it works to be successful. In this hour, you'll learn what makes an object an object, and you'll also learn about collections.

Understanding Objects

Object-oriented programming has been a technical buzzword for quite some time. Almost everywhere you look—the Web, publications, books—you read about objects. What exactly is an object? Strictly speaking, an object is a programming structure that encapsulates data and functionality as a single unit and for which the only public access is through the programming structure's interfaces (properties, methods, and events). In reality, the answer to this question can be somewhat ambiguous because there are so many types of objects—and the number grows almost daily. All objects share specific characteristics, however, such as properties and methods.

The most commonly used objects in Visual C# are the form object and the control object. Earlier hours introduced you to working with forms and controls and even showed you how to set form and control properties. In your Picture Viewer project from Hour 1, for example, you added a picture box and two buttons to a form. Both the PictureBox and the Button controls are control objects, but each is a specific type of control object. Another, less-technical example uses pets. Dogs and cats are definitely different entities (objects), but they both fit into the category of Pet objects. Similarly, text boxes and buttons are each a unique type of object, but they're both considered a control object. This small distinction is important.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus