Introduction to Variables |
|
Definition |
A computer receives information from different applications in various forms. Sometimes a person types it using the keyboard. Sometimes the user clicks the mouse. Sometimes information comes from another, more complicated source. The idea is that the computer spends a great deal of its time with various pieces of information. Information provided to the computer through a program is called datum and the plural is data. Sometimes the word data is used both for singular and plural items. |
Data used by the computer comes and goes regularly as this information changes. For this reason, such information is called a variable. When the user enters data in a program, the computer receives it and must store it somewhere to eventually make it available to the program as needed. For a program used to process employment applications, the types of information a user would enter into the program are the name, the residence, the desired salary, years of experience, education level, etc. Because there can be so much information for the same program, you must specify to the computer what information you are referring to and when. To do this, each category of piece of information must have a name.
To name the variables of your program, you must follow strict rules. In fact, everything else in your program must have a name. C# uses a series of words, called keywords, for its internal use. This means that you must avoid naming your objects using one of these keywords. They are:
Besides these keywords, C# has other words that should be reserved only depending on how and where they are used. These are referred to as contextual keywords and they are:
As mentioned already, the applications we will create display in a dark object called the DOS window. Here is an example showing some values: To display a value in this window, you can enter it in the parentheses of the Console.Write() or Console.WriteLine(). Here are two examples: using System; class Program { static void Main() { Console.WriteLine(248); Console.Write(1); } } If you write Console.WriteLine() with empty parentheses, an empty line would be displayed. In future lessons, we will learn what the meanings of Console, Write(), and WriteLine(). |
|
||
Home | Copyright © 2006-2007 FunctionX, Inc. | Next |
|