views:

17

answers:

2

Hello, I have this code here:

private Func<string, string> RemoveSpecialChars = str => Regex.Replace(str, "[ ./\\-]");

Its complaining (Can not access non-static method Replace in static context) about the call to Replace, because of static context. Whats wrong?

Thanks :)

+1  A: 

The static overload of Regex.Replace has a different signature:

public static string Replace(
    string input,
    string pattern,
    string replacement
)

You're missing the replacement parameter

Thomas Levesque
Ahhhh...didnt see the wood for the trees :D
grady
+1  A: 

You need to use the method Regex.Replace(input,pattern,replacement), the one you use is not static :

private Func<string, string> RemoveSpecialChars = 
                       str => Regex.Replace(str, "[ ./\\-]", replacementString);
madgnome