From 11327c63729387769ae1ace1a1de8fe5cc83ad24 Mon Sep 17 00:00:00 2001 From: Kendra Havens Date: Mon, 3 Dec 2018 19:15:24 -0800 Subject: [PATCH 1/3] Add a new csharp file --- .../core/tutorials/with-visual-studio-code.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/core/tutorials/with-visual-studio-code.md b/docs/core/tutorials/with-visual-studio-code.md index da93afe7d0cb5..4b6277c069b33 100644 --- a/docs/core/tutorials/with-visual-studio-code.md +++ b/docs/core/tutorials/with-visual-studio-code.md @@ -82,6 +82,51 @@ You can also watch a short video tutorial for further setup help on [Windows](ht > [!TIP] > For more information and troubleshooting tips on .NET Core debugging with OmniSharp in Visual Studio Code, see [Instructions for setting up the .NET Core debugger](https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md). +## Add a Class + +1. To add a new class right-click in the VSCode Explorer and select **New File**. This adds a new file to the folder you have open in VSCode. +2. Name your file `Class1.cs`. You must save it with a `.cs` extension at the end for it to be recognized as a csharp file. +3. Add the code below to create your first class. Make sure to include the correct namespace so you can reference it from your `Program.cs` file. +``` csharp +using System; + +namespace HelloWorld +{ + public class Class1 + { + public Class1(){} + public string ReturnMessage() + { + return " Happy coding!"; + } + } +} +``` + +4. Call your new class from your main method in `Program.cs` by adding the code below. + +```csharp +using System; + +namespace HelloWorld +{ + class Program + { + static void Main(string[] args) + { + Class1 c1 = new Class1(); + Console.WriteLine("Hello World!" + c1.ReturnMessage()); + } + } +} +``` + +5. Save your changes and run your program again. The new message should appear with the appended string. +```console +> dotnet run +Hello World! Happy coding! +``` + ## FAQ ### I'm missing required assets to build and debug C# in Visual Studio Code. My debugger says "No Configuration." From 3b6fb1a5825f8c6fd58a22d9171ff63e1f25cb98 Mon Sep 17 00:00:00 2001 From: Kendra Havens Date: Tue, 4 Dec 2018 09:06:50 -0800 Subject: [PATCH 2/3] Remove constructor, add string interpolation --- docs/core/tutorials/with-visual-studio-code.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/core/tutorials/with-visual-studio-code.md b/docs/core/tutorials/with-visual-studio-code.md index 4b6277c069b33..2e6f0aed1452c 100644 --- a/docs/core/tutorials/with-visual-studio-code.md +++ b/docs/core/tutorials/with-visual-studio-code.md @@ -94,10 +94,9 @@ namespace HelloWorld { public class Class1 { - public Class1(){} public string ReturnMessage() { - return " Happy coding!"; + return "Happy coding!"; } } } @@ -115,7 +114,7 @@ namespace HelloWorld static void Main(string[] args) { Class1 c1 = new Class1(); - Console.WriteLine("Hello World!" + c1.ReturnMessage()); + Console.WriteLine($"Hello World! {c1.ReturnMessage()}"); } } } From 3ee2f49ddea4196a8bf759e2942241017333a021 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 5 Dec 2018 11:02:45 -0500 Subject: [PATCH 3/3] respond to feedback --- docs/core/tutorials/with-visual-studio-code.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/tutorials/with-visual-studio-code.md b/docs/core/tutorials/with-visual-studio-code.md index 2e6f0aed1452c..98e004ac98689 100644 --- a/docs/core/tutorials/with-visual-studio-code.md +++ b/docs/core/tutorials/with-visual-studio-code.md @@ -3,7 +3,7 @@ title: Get started with C# and Visual Studio Code - C# Guide description: Learn how to create and debug your first .NET Core application in C# using Visual Studio Code. author: kendrahavens ms.author: mairaw -ms.date: 11/28/2018 +ms.date: 12/05/2018 --- # Get Started with C# and Visual Studio Code @@ -82,7 +82,7 @@ You can also watch a short video tutorial for further setup help on [Windows](ht > [!TIP] > For more information and troubleshooting tips on .NET Core debugging with OmniSharp in Visual Studio Code, see [Instructions for setting up the .NET Core debugger](https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md). -## Add a Class +## Add a class 1. To add a new class right-click in the VSCode Explorer and select **New File**. This adds a new file to the folder you have open in VSCode. 2. Name your file `Class1.cs`. You must save it with a `.cs` extension at the end for it to be recognized as a csharp file.