C# static class Edit

Rakesh Kumar Sutar | 20 January 2021 | 1274


A static class cannot be instantiated. In other words, you cannot use the new operator to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself.


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World

    class Programs
        static void Main(String[] args)
            var result = Calculator.Sum(10, 25); 

            var calcType = Calculator.Type; 
            Calculator.Type = "Scientific";

            Console.WriteLine("\t" calcType);
            Console.WriteLine("\t" result);

    public static class Calculator
        private static int resultStorage = 0;

        public static string Type = "Arithmetic";

        public static int Sum(int num1, int num2)
            return num1   num2;

        public static void Store(int result)
            resultStorage = result;