Hour 11. Using Constants, Data Types, Variables, and Arrays


What You'll Learn in This Hour:

  • Understanding data types

  • Determining data type

  • Converting data to different data types

  • Defining and using constants

  • Declaring and referencing variables

  • Working with arrays

  • Determining scope

  • Declaring static variables

  • Using a naming convention

As you write your Visual C# methods, you'll regularly need to store and retrieve various pieces of information. In fact, I can't think of a single application I've written that didn't need to store and retrieve data in code. For example, you might want to keep track of how many times a method has been called, or you may want to store a property value and use it at a later time. Such data can be stored as constants, variables, or arrays. Constants are named values that you define once at design time and cannot be changed after that, but can be referenced as often as needed. Variables, on the other hand, are like storage bins; you can retrieve or replace the data in a variable as often as you need to. Arrays act like grouped variables, enabling you to store many values in a single array variable.

Whenever you define one of these storage entities, you have to decide the type of data it will contain. For example, is a new variable going to hold a string value (text) or perhaps a number? If it will hold a number, is the number a whole number, an integer, or something else entirely? After you determine the type of data to store, you must choose the level of visibility that the data has to other methods within the project (this visibility is known as scope). In this hour, you'll learn the ins and outs of Visual C# data types, how to create and use these "storage" mechanisms, and how to minimize problems in your code by reducing scope.

By the Way

In this hour you'll build on the Picture Viewer project from Hour 10, "Creating and Calling Methods." Here, you'll start the process for hooking up the features you created controls for on your Options form.





Sams Teach Yourself Microsoft Visual C# 2005 in 24 Hours, Complete Starter Kit
Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
ISBN: 0672327406
EAN: 2147483647
Year: N/A
Pages: 248
Authors: James Foxall

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net