Ok, i'm well and truly stumped here.
I've written extension methods before, and never had any problems. However, i've never had to use them in Console Apps. The following code won't compile and I have no idea why! I created a simple console app to try it out and it just won't work:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "hello";
Console.WriteLine(s.TestMethod());
Console.Read();
}
}
public static class ExtensionTest
{
public static string TestMethod(this string input)
{
return input.ToUpper();
}
}
}
Can anyone see what's wrong here?
The first error i'm running into is "Type expected" on line 21, which is:
(this string input)
I know i could quite easily just change to:
Console.WriteLine(ExtensionTest.TestMethod(s));
But i'd really like to know why i can't write this extension method in a console app.
Thanks for any help!