c# in visual studio code code example

Example 1: how to make a C# application visual studio code

mkdir MyApp; cd MyApp;
dotnet new console

Example 2: simple program in c# for vs code .net console

//You should start writing your own code this will give you a headstart (This is tooken from Brakeys tut )

using System;

namespace C__Learning   // Here Input Your Folder Name.
{
    class Program
    {
        static void Main(string[] args)
        {
            //Change the color of Text
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Title = "C#Learning";
            Console.WindowHeight = 40;
			//Creating Var for input
            Double num01;
            Double num02;
			//Writing a line in terminal saying Input a number:
            Console.Write(" Input a number: ");
			//converting it to a double because its og is a string
            num01 = Convert.ToDouble( Console.ReadLine());
			// gettin a second number
            Console.Write("Input a second number: ");
			//converting it to a double because its og is a string again
            num02 = Convert.ToDouble( Console.ReadLine());
			// multiplying both the numbers
            Double result = num01 * num02;
			//Giving the Result
            Console.WriteLine("The result is " + result);
            
            //Waiting for a key too close the program At the end
            Console.ReadKey();

        }
    }
}

// this is for educational purposes.

Example 3: how to run csharp in visual studio code

/*
You should have a application if you want to create a application go 
the folder which is your project now use the command in the dir use the 
command dotnet new console to intialize it as a console application. Now 
You will the a file called {You workspace}.csproj go to the file and run it
*/

Example 4: visual c#

class Calculator
{
    public static double DoOperation(double num1, double num2, string op)
    {
        double result = double.NaN; // Default value is "not-a-number" which we use if an operation, such as division, could result in an error.

        // Use a switch statement to do the math.
        switch (op)
        {
            case "a":
                result = num1 + num2;
                break;
            case "s":
                result = num1 - num2;
                break;
            case "m":
                result = num1 * num2;
                break;
            case "d":
                // Ask the user to enter a non-zero divisor.
                if (num2 != 0)
                {
                    result = num1 / num2;
                }
                break;
            // Return text for an incorrect option entry.
            default:
                break;
        }
        return result;
    }
}