Home

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.

Practical LearningPractical Learning: Introducing Variables

  1. Microsoft Visual C# 2005 Express Edition or Microsoft Visual C# 2005 Professional
     
    From now on, we will only refer to Microsoft Visual C#
  2. To create a new application, on the Start Page, on the right side of Create, click Project
  3. In the Templates section, click Console Application
  4. Change the Name to GeorgetownCleaningServices2 and click OK

Names in C#

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:

 

Once you avoid these words, there are rules you must follow when naming your objects. On this site, here are the rules we will follow:

  • The name must start with a letter or an underscore
  • After the first letter or underscore, the name can have letters, digits, and/or underscores
  • The name must not have any special characters other than the underscore
  • The name cannot have a space

Besides these rules, you can also create your own but that abide by the above.

C# is case-sensitive. This means that the names Case, case, and CASE are completely different. For example, main is always written Main.

Values and Variables on the Console

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