C# create a simple class and create object in main

In this example, we create a simple class, and create its object in main function:

namespace ConsoleApplication1
{
    class Test
    {
     public   int a;
     public   int b;
    }

    class Program
    {
        static void Main(string[] args)
        {
            int first = 20;
            int second = 30;

            Console.WriteLine(first + " " + second);
            first = second;
            first = 1000;

            Console.WriteLine(first + " " + second);
            

            
            Test t = new Test();
            t.a = 10;
            t.b = 20;

            Console.WriteLine(t.a + " " + t.b);

            Test t1 = t;
            t1.a = 100;
            t1.b = 200;

            Console.WriteLine(t1.a + " " + t1.b);
            Console.WriteLine(t.a + " " + t.b);

            Test t3 = new Test();
            t3.a = 111;
            t3.b = 222;

            Console.WriteLine(t3.a + " " + t3.b);
        
              }

      

        }
    

}

 

Add a Comment

Your email address will not be published. Required fields are marked *