How to do it...

  1. Open Visual Studio 2017.
  2. 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:
  1. 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:
  1. Now Click OK.
  2. 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. 
  3. At the end of the Main method, type the following code snippet: 
      private static string SayHello(string yourName)
{
return $"Hello, {yourName}";
}
  1. 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();
  1. 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}";
}
  1. Let's hit F5 and test the application. If everything is OK, you should see the following screen. Press Enter to exit: 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.190.167