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

   

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

graphics/newterm.gif

As you write your 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, v ariables, or arrays. Constants are named values that you define once at design time but that 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, allowing you to store many values in a single array variable.

graphics/newterm.gif

Whenever you define one of these storage entities, you must 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 C# new data types, how to create and use these "storage" mechanisms, and you'll learn how to minimize problems in your code by reducing scope.

The highlights of this hour include the following:

  • Understanding data types

  • Determining data type

  • Converting data to different data types

  • Defining and using constants

  • Dimensioning and referencing variables

  • Working with arrays

  • Determining scope

  • Using a naming convention


graphics/bookpencil.gif

I cover a lot of important material in this hour, but you'll notice a lack of hands-on examples. You're going to use variables throughout the rest of this book, and you've already used them in earlier hours. I've used the space in this hour to teach you the meat of the subject; you'll get experience with the material in other hours.


   
Top


Sams Teach Yourself C# in 24 Hours
Sams Teach Yourself Visual Basic 2010 in 24 Hours Complete Starter Kit (Sams Teach Yourself -- Hours)
ISBN: 0672331136
EAN: 2147483647
Year: 2002
Pages: 253
Authors: James Foxall

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