ideas | discover | explore

Showing posts with label Hello World. Show all posts
Showing posts with label Hello World. Show all posts

Friday, October 28, 2011

C# 12 - Multidimensional Arrays - Multiplication Table

Manage and share your stuff. Sign up now for FREE!
meestuf.com

-----------------------------------------------------------------------------------------------------

1. Create a new console project.

2. Edit the Program.cs inside static void Main(string[] args) file as shown below.
static void Main(string[] args)
        {
            int[,] multiplicationTable = new int[11,11];
 
            for (int i = 1; i < 11; i++)
                for (int x = 1; x < 11; x++)
                    multiplicationTable[i, x] = i * x;
 
            Console.Write("x".PadRight(3) + "|");
            for (int i = 1; i < 11; i++)
            {
                Console.Write(i.ToString().PadRight(3) + "|");
            }
            Console.Write("\n");
            Console.WriteLine("--------------------------------------------");
 
            for (int i = 1; i < 11; i++)
            {
                Console.Write(i.ToString().PadRight(3) + "|");
                for (int x = 1; x < 11; x++)
                {
                    Console.Write(multiplicationTable[i, x].ToString().PadRight(3) + "|");
                }
                Console.Write("\n");
                Console.WriteLine("--------------------------------------------");
            }
 
            Console.ReadLine();
       }       

3.       Press F5 to run and see the results.


4. Thank you.

Rectangular array is another type of array that allows you to define a table like array that has a row and column definition.

Syntax:

type[,] = new type[row,column];

type – can be any data type
row – is the number of rows for your table
column – is the number of columns for your table

e.g.
                int[,] mytable = new int[10, 5];

-----------------------------------------------------------------------------------------------------
Manage and share your stuff. Sign up now for FREE!
meestuf.com

Monday, August 22, 2011

C# 1 – Hello World

1.  Go to File -> New -> Project… .
2.  On the left side under Installed Templates select Visual C# -> Windows. On the right side select Console Application. Enter HelloWorld on the Name. Click OK.


3.  In the opened Program.cs file. Look for the part where it says
    static void Main(string[] args)
        {
        }


4.  Enter the following code in between the curly braces “{“ and “}”.
    Console.Write("Hello World Again!");

5.  Your screen will now look like this.


6.  To execute or run your code press F5. You can also press the Play button like the one shown below.
7.  You’re probably wondering what happened when you tried to run the code and you noticed only slight flicker on your screen. The code actually executed very fast that it felt like you never saw the results of the code. Add the following code below on the next line after Console.Write.

8.  Press F5 to run and see the result.

9.  Congratulations! You’ve just run your first program. Take a break for now and enjoy life. Watch out for my next episode.

10.  Thank you.