In Java, the inner static class has no hidden access to members of its closing type. In C #, all nested types do not have this access to their parent types; there is no modifier that needs to be added in C # to cause this behavior.
In C # classes, static abstract sealed , so they cannot be created or produced, is not the same value as in Java. In addition, interfaces cannot contain their own type declarations.
Try something like this:
public interface IActivation { double Func(double inputput); } public class S1 : IActivation { public static readonly S1 Instance = new S1(); private S1() { } public double Func(double input) { if (input > 0) return 1.0; return 0.0; } }
If your goal is to provide a default implementation in some βreadableβ way (although I argue that IActivator.S1() is inherently more readable ...), you can create a static factory class:
public static class Activator { public static S1 S1 { get { return S1.Instance;
However, I dispute the claim that it is more readable or useful. When creating an object in the context of a certain type, Visual Studio displays all subtypes of this type. So, if you do this ( | represents the cursor):
IActivator foo = new |
You should get a neat list of all the classes in your current area that implement IActivotor.
source share