
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open Visual Studio 2017.
- Click File | New | Project and, in the New Project template dialog box, select Visual C# in the left-hand pane and Console App (.NET Framework) in the right-hand pane:

- In the Name: text box, type a name for your application. In this case, type HelloCSharp. Select a preferred location in the Location: drop-down list or click the Browse... button and select a location. Leave the defaults as they are:

- Now Click OK.
- You will be presented with a default code template for a C# console application. Let's hit F5 to give it a test run. If everything is fine, a console will pop up and close.
- At the end of the Main method, type the following code snippet:
private static string SayHello(string yourName)
{
return $"Hello, {yourName}";
}
- Now, inside your Main method, type the code that calls the previous method we just created:
var message = SayHello("Fiqri Ismail");
Console.WriteLine(message);
Console.ReadLine();
- Now we have written our first C# code. The code of the console app should look like the following after you are done coding:
static void Main(string[] args)
{
var message = SayHello("Fiqri Ismail");
Console.WriteLine(message);
Console.ReadLine();
}
private static string SayHello(string yourName)
{
return $"Hello, {yourName}";
}
- Let's hit F5 and test the application. If everything is OK, you should see the following screen. Press Enter to exit:
