Extension Methods Discoverability : Extension Method : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » Extension Method »

 

Extension Methods Discoverability








    
 

using System;

class Class1 {
}

class Class2 {
    public void Method1(string s) {
        Console.WriteLine("Class2.Method1");
    }
}

class Class3 {
    public void Method1(object o) {
        Console.WriteLine("Class3.Method1");
    }
}

class Class4 {
    public void Method1(int i) {
        Console.WriteLine("Class4.Method1");
    }
}

static class Extensions {
    static public void Method1(this object o, int i) {
        Console.WriteLine("Extensions.Method1");
    }

    static void Main() {
        new Class1().Method1(12); // Extensions.Method1 is called
        new Class2().Method1(12); // Extensions.Method1 is called
        new Class3().Method1(12); // Class3.Method1 is called
        new Class4().Method1(12); // Class4.Method1 is called
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» Extension Method