Simple, Quality, Awesome Software

Variables Everywhere

Below is the complete code for the Variables Everywhere Try It Out! problem.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpBook.Examples.VariablesEverywhere
{
    class Program
    {
        static void Main(string[] args)
        {
            // A variable that can store text.
            string text;
            text = "Hello World!";
            Console.WriteLine(text);

            // Note that any variable can be initialized on the line they are
            // declared as well.
            string message = "Real Klingons don't eat quiche.";

            // subsequent accesses to the variable don't require you to use the
            // type any more.
            message = "My Spidey senses are tingling.";
            message = "To the Bat Cave!";
            Console.WriteLine(message);

            // Bytes for very small numbers--often used in large groups to push
            // raw data around.
            byte tinyNumber;
            tinyNumber = 3;
            Console.WriteLine(tinyNumber);

            // Signed bytes
            sbyte tinySignedNumber;
            tinySignedNumber = -17;
            Console.WriteLine(tinySignedNumber);

            // Shorts for smallish numbers
            short smallNumber;
            smallNumber = -4843;
            Console.WriteLine(smallNumber);

            // And the unsigned version.
            ushort smallUnsignedNumber;
            smallUnsignedNumber = 35000;
            Console.WriteLine(smallUnsignedNumber);

            // Ints are quite popular. Not too big, not too small.
            int mediumNumber;
            mediumNumber = 394309395;
            Console.WriteLine(mediumNumber);

            // Goes higher than the signed version, but doesn't include negatives.
            uint mediumUnsignedNumber;
            mediumUnsignedNumber = 464637838;
            Console.WriteLine(mediumUnsignedNumber);

            // Longs can be quite large.
            long largeNumber;
            largeNumber = -395682658206520568;
            Console.WriteLine(largeNumber);

            // Unsigned longs can reach the highest integer values for the
            // integral types.
            ulong largeUnsignedNumber;
            largeUnsignedNumber = 3533535626582065205;
            Console.WriteLine(largeUnsignedNumber);

            // char is for storing single letters.
            char singleLetter;
            singleLetter = 'p';
            Console.WriteLine(singleLetter);

            // Floats can store quite a big range, but...
            float pi;
            pi = 3.141593f;
            Console.WriteLine(pi);

            // Doubles can store much more.
            double piAsDouble;
            piAsDouble = 3.14159265358979;
            Console.WriteLine(piAsDouble);

            // The decimal type can't go as high, but it is far more accurate.
            decimal piAsDecimal;
            piAsDecimal = 3.1415926535897932384626433833M;
            Console.WriteLine(piAsDecimal);

            // These may seem strange right now, but we'll use them in decision
            // making before long.
            bool truthValue;
            truthValue = true;
            Console.WriteLine(truthValue);
            truthValue = false;
            Console.WriteLine(truthValue);

            Console.ReadKey();
        }
    }
}