public static class Helper
{
public static float ToFloat(this string input)
{
float result;
return float.TryParse(input, out result) ? result : 0;
}
}
I have added the following at top:
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method)]
public class ExtensionAttribute : Attribute
{
public ExtensionAttribute()
{
}
}
}
But still I get Type expected error on “this” in Helper class. What’s the problem ?
Weird, the following compiles and runs fine when targeting .NET 2.0: