Extension Methods in C# 3.0

program.cs

using System;

namespace Extension
{
 

    class DekhiKiObostha
    {
        public void Test1()
        {
            Console.WriteLine("Method-1");
        }

        public void Test2()
        {
            Console.WriteLine("Method-2");
        }
        public void KiObostha()
        {
            Console.WriteLine("Hello Vai Koi Jaben ?");
        }
      
       
    }
}

StaticClass.cs

using System;

namespace Extension
{
    static class StaticClass
    {
        public static void Test3(this DekhiKiObostha s,int i)
        {
            Console.WriteLine("Method-3 :"+i);
        }


    }


    static class DclassTest
    {
        public static void TestDekhi(this DekhiKiObostha zaDekhiKiObostha,int o)
        {
            Console.WriteLine("Dlclass Test eta ="+o);
        }
    }
}

TestExtensionMethods.cs

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

namespace Extension
{
    class TestDekhi
    {
          static void Main()
        {

            DekhiKiObostha dd = new DekhiKiObostha();

            dd.Test1();
            dd.Test2();
            dd.Test3(10);
            dd.KiObostha();
            dd.TestDekhi(8);
            Console.ReadKey();
        }
       
    }
}

 

 

 

 

 

 

 

output:

Method-1
Method-2
Method-3 :10
Hello Vai Koi Jaben ?
Dlclass Test eta =8

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.