@@ -263,6 +263,7 @@ The set of members of an interface declared in multiple parts ([§15.2.7](classe
263263
264264Consider an interface with a default implementation for a member ` M ` . As ` M ` is not part of that interface’s contract, outside that interface or any interface derived from it, that name is not visible. How then can it be accessed? The following code shows how:
265265
266+ <!-- Example: {template:"standalone-console", name:"InterfaceMember", expectedOutput:["IB.M", "IA.P = 10", "IB.P = 20"]} -->
266267``` csharp
267268interface IA
268269{
@@ -273,7 +274,7 @@ interface IA
273274 }
274275}
275276
276- interface IB : IA
277+ interface IB : IA
277278{
278279 public new int P { get { return 20 ; } }
279280 void IA.M()
@@ -282,11 +283,11 @@ interface IB : IA
282283 }
283284}
284285
285- class C : IB { }
286+ class C : IB { }
286287
287288class Test
288289{
289- public static void Start ()
290+ public static void Main ()
290291 {
291292 C c = new C ();
292293 ((IA )c ).M (); // cast needed
@@ -324,11 +325,11 @@ As a static *field_declaration* is considered to have a default implementation (
324325
325326> * Example* : The following program contains static members of various kinds:
326327>
328+ > <!-- Example: {template:"standalone-console", name:"InterfaceFields", inferOutput:true} -->
327329> ``` csharp
328- > using System ;
329330> public interface IX
330331> {
331- > private const int constant = 100;
332+ > public const int constant = 100;
332333> protected static int field;
333334>
334335> static IX()
@@ -338,7 +339,10 @@ As a static *field_declaration* is considered to have a default implementation (
338339> field = 50 ;
339340> Console .WriteLine (" static constructor has run" );
340341> }
341- >
342+ > }
343+ >
344+ > public class Test : IX
345+ > {
342346> public static void Main ()
343347> {
344348> Console .WriteLine ($" constant = {IX .constant }, field = {IX .field }" );
@@ -405,9 +409,9 @@ These rules ensure that any covariant or contravariant usage of the interface re
405409> < ! -- FIX : need to define I < T > , then perhaps break into 2 files , first one a standalone - lib , the second , code - in - class-lib. -->
406410> ```csharp
407411> class B {}
408- > class D : B {}
409- > class E : B {}
410- > class C : I <D >
412+ > class D : B {}
413+ > class E : B {}
414+ > class C : I <D >
411415> {
412416> public void M <U >() {.. .}
413417> }
@@ -430,13 +434,14 @@ A virtual method with implementation declared in an interface may be overridden
430434
431435> *Example*:
432436>
437+ > <!-- Example : {template :"standalone -lib -without -using ", name :"InterfaceMethods2 "} -->
433438> ```csharp
434439> interface IA
435440> {
436441> void M () { Console .WriteLine (" IA.M" ); }
437442> }
438443>
439- > interface IB : IA
444+ > interface IB : IA
440445> {
441446> abstract void IA.M(); // reabstraction of M
442447 > }
@@ -448,13 +453,14 @@ Reabstraction is also permissible in an implementing class.
448453
449454> *Example *:
450455>
456+ > < ! -- Example : {template : " standalone-lib-without-using" , name : " InterfaceMethods3" } -- >
451457> ```csharp
452458> interface I1
453459> {
454460> void M () { }
455461> }
456462>
457- > abstract class C : I1
463+ > abstract class C : I1
458464> {
459465> public abstract void M (); // implement I1.M with an abstract method in C
460466 > }
@@ -471,6 +477,7 @@ One override `M1` is considered *more specific* than another override `M2` if `M
471477
472478> *Example*:
473479>
480+ > <!-- Example : {template :"standalone -lib -without -using ", name :"InterfaceMethods4 ", expectedErrors :["CS8705"]} -->
474481> ```csharp
475482> interface IA
476483> {
@@ -482,14 +489,14 @@ One override `M1` is considered *more specific* than another override `M2` if `M
482489> void IA.M() { Console.WriteLine("IB.M"); }
483490> }
484491>
485- > interface IC : IA
492+ > interface IC : IA
486493> {
487494> void IA.M() { Console.WriteLine("IC.M"); }
488495> }
489496>
490- > abstract class C : IB , IC { } // error: no most specific override for 'IA.M'
497+ > abstract class C : IB , IC { } // error: no most specific override for 'IA.M'
491498>
492- > abstract class D : IA , IB , IC // OK
499+ > abstract class D : IA , IB , IC // OK
493500 > {
494501> public abstract void M ();
495502> }
@@ -501,6 +508,7 @@ It is an error if in a class declaration the most specific override of some inte
501508
502509> *Example *:
503510>
511+ > < ! -- Example : {template : " standalone-lib-without-using" , name : " InterfaceMethods5" , expectedErrors : [" CS0535" ]} -- >
504512> ```csharp
505513> interface IF
506514> {
@@ -587,6 +595,7 @@ It is an error to declare a class type, struct type, or enum type within the sco
587595
588596> *Example*: The declaration of `C ` below is an error .
589597>
598+ > <!-- Example : {template :"standalone -lib -without -using ", name :"InterfaceNestedTypes ", expectedErrors :["CS8427"]} -->
590599> ```csharp
591600> interface IOuter <out T >
592601> {
0 commit comments