Related: How do I create a static local variable in Java?
Pardon if this is a duplicate; I was pretty sure this would have been
No, C# does not support this. You can come close with:
private static System.Text.RegularExpressions.Regex re =
new System.Text.RegularExpressions.Regex("\\(copy (\\d+)\\)$");
private static string AppendCopyToFileName(string f)
{
}
The only difference here is the visibility of 're'. It is exposed to the classm not just to the method.
The re
variable will be initialized the first time the containing class is used in some way. So keep this in a specialized small class.