Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>C/C++/C# ExtensionNew to Visual Studio Code? Get it now.
C/C++/C# Extension

C/C++/C# Extension

Daryoush Alipour tirotir

|
588 installs
| (0) | Free
An extension for running C, C++, and C# code with comprehensive tutorial snippets and a seamless execution workflow.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

C/C++/C# Extension for Visual Studio Code

This extension provides a seamless and efficient development experience for C, C++, and C# within Visual Studio Code. It includes:

  • Tutorial Snippets: Step-by-step code examples covering fundamental and advanced programming concepts in C, C++, and C#, enabling users to learn while coding.
  • Run Code Feature: Compile and execute your programs directly from VS Code, streamlining your workflow and improving productivity.

With this extension, developers can quickly prototype, test, and debug their code while leveraging the powerful features of Visual Studio Code.


Prerequisites

Ensure the necessary tools and compilers are installed on your system.

General Requirements

  1. Visual Studio Code: Download VS Code.

Language-Specific Setup

C/C++

Install a C/C++ compiler:

  • Windows: Install MinGW or TDM-GCC and add gcc/g++ to your PATH.

    • MinGW Installation Guide.
  • Linux: Install GCC/G++:

    sudo apt update
    sudo apt install build-essential
    
  • macOS: Install Xcode Command Line Tools:

    xcode-select --install
    

C# Setup and Requirements

To compile and run C# programs, you need the following:

  1. Install the .NET SDK (required for Windows, Linux, and macOS).
  2. Optionally, install Mono (useful for running C# programs on Linux/MacOS).

Ensure a Valid .NET Project

C# programs require a .cs file to be part of a valid .NET project. Without a properly configured .csproj file, the build will fail.

  1. Check if the folder contains a .csproj file:

    • For example: MyProject.csproj.
  2. If a project file is missing, create a new one by running the following command in your terminal:

    dotnet new console -n MyProject
    

    Example:

    dotnet new console -n test1
    
  3. Navigate to the project directory:

    cd MyProject
    

    Example:

    cd test1
    

Run the Program

Once the .NET project is set up, you can run the program using Visual Studio Code or the terminal:

Using VS Code

  1. Open Program.cs in VS Code.
  2. Press Ctrl+Shift+P (or F1) to open the Command Palette.
  3. Choose Run Code (extension.runCode).

Using the Terminal

  1. Run the program directly from the terminal:

    dotnet run --project <ProjectPath>
    

    Example:

    dotnet run --project test1.csproj
    

This setup ensures smooth compilation and execution of your C# programs within a .NET environment.


Installation

  1. Open VS Code.
  2. Navigate to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS).
  3. Search for "C/C++/C# Extension" and click Install.

Usage

Snippets

  1. Open a .c, .cpp, or .cs file.
  2. Start typing a snippet prefix (e.g., c-tutorial) and press Tab to expand.
  3. Modify the boilerplate as needed.

Running Code

  1. Open a file (.c, .cpp, or .cs).
  2. Press Ctrl+Shift+P (Cmd+Shift+P on macOS) and type Run Code.
  3. Select the option to compile and run your code.

Manual Compilation

  • C/C++: Use gcc or g++.
  • C#: Use dotnet or csc.

Features

Tutorial Snippets

This extension includes comprehensive tutorial snippets for C, C++, and C# programming languages. These snippets are designed to help beginners and intermediate programmers quickly understand and practice the core concepts of each language. Each tutorial snippet provides a step-by-step guide with full examples, starting from "Hello, World!" to more advanced topics like loops, conditionals, functions, classes, and basic file I/O.

  • C Tutorial: Includes 15 examples such as variable declarations, arrays, pointers, structures, and recursion.
  • C++ Tutorial: Covers essential topics like variable initialization, classes and objects, templates, and dynamic memory allocation.
  • C# Tutorial: Offers full examples of variables, arrays, conditionals, loops, methods, classes, and inheritance.

Users can type the prefix (c-tutorial, cpp-tutorial, or csharp-tutorial) in their respective .c, .cpp, or .cs files to insert the entire tutorial snippet, making it easy to copy-paste code and experiment in their own projects.

"Run Code" Integration

  • C: Compiles with gcc.
  • C++: Compiles with g++.
  • C#: Uses .NET SDK or Mono.

Task Automation

Preconfigured tasks for building and running each language. Use Ctrl+Shift+B or configure custom keybindings.


Troubleshooting

  • Command Errors:

    • Ensure compilers are in your PATH.
    • For .NET issues, verify the SDK is installed.
  • Snippet Issues:

    • Ensure you're using the correct file extension (.c, .cpp, .cs).
    • Type the appropriate prefix (e.g., c-tutorial, cpp-tutorial).

License

Licensed under the MIT License. See the LICENSE file for details.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft