Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
static class Program{ //[ExtensionAttribute()] static void DisplayInterval(this Timer t) { Console.WriteLine(t.Interval.ToString()); } static void Main(string[] args) { System.Timers.Timer t = new System.Timers.Timer(2000); Program.DisplayInterval(t); // long hand usage of method t.DisplayInterval(); // short hand usage of method (extension) Console.ReadLine(); }}
"Cannot use 'this' modifier on first parameter of method declaration without a reference to System.Core.dll. Add a reference to System.Core.dll or remove 'this' modifier from the method declaration"
"You are using the 'this' modifier and it depends on the ExtensionAttribute that itself resides in the System.Core.dll and you do not have a reference to it"
namespace System.Runtime.CompilerServices{ public class ExtensionAttribute : Attribute { }}
using System.Runtime.CompilerServices;
using Moth.Linq;static class Program{ static void Main(string[] args) { var ints = new []{1,2,3,4}; var res2 = from p in ints where p > 2 select p; System.Diagnostics.Debugger.Break(); // examine res2 Console.ReadLine(); }}