官术网_书友最值得收藏!

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: 
主站蜘蛛池模板: 北辰区| 赤峰市| 稻城县| 镇沅| 农安县| 霸州市| 射阳县| 本溪| 沧源| 临邑县| 宾川县| 宁河县| 江达县| 嘉定区| 溧水县| 丹寨县| 临潭县| 鹤山市| 贵溪市| 南开区| 崇文区| 邓州市| 连州市| 皋兰县| 保康县| 六盘水市| 乐亭县| 甘德县| 五家渠市| 甘南县| 榕江县| 三都| 定西市| 垫江县| 清涧县| 轮台县| 高青县| 凌海市| 池州市| 赞皇县| 大邑县|