C# Archives - IAMCP-US https://www.iamcp-us.org Thu, 01 Jul 2021 14:52:47 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.3 https://www.iamcp-us.org/wp-content/uploads/2021/07/cropped-code-blocks-icon-32x32.png C# Archives - IAMCP-US https://www.iamcp-us.org 32 32 Hello World! in C # https://www.iamcp-us.org/hello-world-in-c/ https://www.iamcp-us.org/hello-world-in-c/#respond Thu, 01 Jul 2021 14:52:45 +0000 https://www.iamcp-us.org/?p=554 If you’ve ever studied programming languages, you probably know that it all starts with the “Hello, world!” Who are we to break this tradition? Launch Visual Studio Community (presented in the previous thread) and select File -> New -> Project. …

The post Hello World! in C # appeared first on IAMCP-US.

]]>
If you’ve ever studied programming languages, you probably know that it all starts with the “Hello, world!” Who are we to break this tradition? Launch Visual Studio Community (presented in the previous thread) and select File -> New -> Project. In the window that appears, select Console Application (.NET framework). This is the most common type of application on Windows, but ideal for language learning. Once you click OK, Visual Studio will create a new project, including the Program.cs file, which contains “all the juice” of the program and looks something like this:

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

namespace ConsoleApp1
{
    class Program
    {
    static void Main(string[] args)
    {
    }
    }
}

In fact, these lines don’t really do much, or at least they seem to. Try running the program by pressing F5 on your keyboard. This will force Visual Studio to compile and run your code, but you will most likely see a black window start and close. This is due to the fact that the program does nothing yet. In the next topic we will go through the lines of code and understand what they are for, but for now we just want to see the output of the program, so let’s pretend we know everything about C # and add a couple of lines to see the output of the code. In the last couple {} add the following lines:

Console.WriteLine("Hello, world!");
Console.ReadLine();

Your first program should now look like this:

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

namespace ConsoleApp1
{
    class Program
    {
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, world!");
        Console.ReadLine();
    }
    }
}

Press F5 again and run the program. You will see a black window, which now does not close immediately after opening. You will also see your “Hello” to the world. Okay, we’ve added two lines to the code, but what do they do? One of the great things about C # and the .NET framework is that most of the code is legible, even to the untrained eye. This is what this example shows.

The first line of code uses the console to output a line of text, and the second reads the text from the console. Reads? What for? This is actually a little trick, because without it, the program would instantly close the output window before you saw anything.

The post Hello World! in C # appeared first on IAMCP-US.

]]>
https://www.iamcp-us.org/hello-world-in-c/feed/ 0