Home:ALL Converter>How can i implement a class using :Interface?

How can i implement a class using :Interface?

Ask Time:2012-01-02T04:05:30         Author:user1074030

Json Formatter

How can i implement a method from a class that is extended to an Interface?

I have this Interface:

public Interface myInterface
{
      public static int myMethod();
}

And this class:

public class MyClass : myInterface
{
       // And I want here to implement the method form myInterface and i don't know how
}

Author:user1074030,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8695196/how-can-i-implement-a-class-using-interface
Yahia :

Interface won't compile - change it to interface.\nstatic can't be part of an interface.\n\nAfter corrections the code would look like this for example:\n\npublic interface myInterface\n{\n int myMethod();\n}\n\npublic class MyClass : myInterface\n{\n public int myMethod()\n {\n return 1;\n }\n}\n\n\nRegarding static and interface see a quote from http://channel9.msdn.com/forums/TechOff/250972-Static-Inheritance/?CommentID=274217 :\n\n\n Inheritance in .NET works only on instance base. Static methods are defined on the type level not on the instance level. That is why\n overriding doesn't work with static methods/properties/events...\n \n Static methods are only held once in memory. There is no virtual table etc. that is created for them.\n \n If you invoke an instance method in .NET, you always give it the current instance. This is hidden by the .NET runtime, but it happens.\n Each instance method has as first argument a pointer (reference) to\n the object that the method is run on. This doesn't happen with static\n methods (as they are defined on type level). How should the compiler\n decide to select the method to invoke?\n",
2012-01-01T20:11:55
Eugene Cheverda :

You declared your interface incorrectly. Interface in C# specified with interface keyword, in that exact casing. Also interfaces cannot contain static methods. For further details please refer to Interfaces (C# Programming Guide) MSDN article.",
2012-01-01T20:14:20
yy