PRACTICAL 1: CONSOLE APPLICATION (CALCULATOR) AND RAZOR PAGE

A. CONSOLE APPLICATION - SIMPLE CALCULATOR

STEPS:
1. Open Visual Studio and click "Create a new project".
2. Select "Console App" and click Next.
3. Give the project name and directory (location), then click Create.
4. Write the code given below in Program.cs.
5. Press F5 (or Ctrl+F5) to run the program and enter the values.

CODE: (Program.cs)
using System;

namespace p1_evenodd
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 0;
            double b = 0;
            Console.WriteLine("enter num1");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("enter num2");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("select operator(+,-,*,/)");
            Console.WriteLine("\ta.Add");
            Console.WriteLine("\tb.Sub");
            Console.WriteLine("\tc.Mul");
            Console.WriteLine("\td.Div");
            string op = Console.ReadLine().ToLower();
            switch (op)
            {
                case "a":
                    Console.WriteLine(a + b);
                    break;
                case "b":
                    Console.WriteLine(a - b);
                    break;
                case "c":
                    Console.WriteLine(a * b);
                    break;
                case "d":
                    Console.WriteLine(a / b);
                    break;
            }
        }
    }
}

OUTPUT:
enter num1
5
enter num2
2
select operator(+,-,*,/)
        a.Add
        b.Sub
        c.Mul
        d.Div
d
2.5

(a -> 7,  c -> 10,  d -> 2.5 for the inputs 5 and 2)


B. RAZOR PAGE

STEPS:
1. Create a new project and select "ASP.NET Core Web Application", then click Next.
2. Give the project name and click Create.
3. Select the "Empty" template and click Create.
4. In Solution Explorer, right click on the project -> Add -> New Item.
5. Select "Razor Page" and click Add (e.g. Index.cshtml).

Index.cshtml generated by the Razor Page template:
@page
@model WebApplication1.IndexModel
@{
}
