I have this piece of code, and I would like to know why this is output, as written in the comment below:
interface I { void m1(); void m2(); void m3(); } class A : I { public void m1() { Console.WriteLine("A.m1()"); } public virtual void m2() { Console.WriteLine("A.m2()"); } public virtual void m3() { Console.WriteLine("A.m3()"); } } class C : A, I { public new void m1() { Console.WriteLine("C.m1()"); } public override void m2() { Console.WriteLine("C.m2()"); } public new void m3() { Console.WriteLine("C.m3()"); } } ------ C c = new C(); ((I) ((A) c)).m1(); //"C.m1()" ((I) ((A) c)).m2(); //"C.m2()" ((I) ((A) c)).m3(); //"C.m3()"
One of the initial assumptions about what came out:
A.m1 ();C.m2 ();A.m3 ();
All these type conversions are redundant, and I'm sure they will be optimized by the compiler.
. (A) c , C - A, (I)c, , C I. , C, .
(A) c
C
A
(I)c
I
, . , :
C , C. I.M, I - , M, S, C C, :S , I M, I.M., S , M, I.M.
C , C. I.M, I - , M, S, C C, :
I.M
M
S
C :
class C : A { public new void m1() { Console.WriteLine("C.m1()"); } public override void m2() { Console.WriteLine("C.m2()"); } public new void m3() { Console.WriteLine("C.m3()"); } }
:
# , , , . CLR , . , ; . , ( ); .
, . . .
C I, C, , , (.. C), , C ( A ).
, , - .
, C . . A. ? . . . I. ? . . . .
.
, "A" . , I, . , " , , , , " I.m1 ".
- . "". , . , " , 3 ", , - , , .
. , , "" . , , , , , I, .
?
, C A I.
((I) ((A) c)). m1() ((I) ((A) c)). m3():- "" A.m1 ( ). C.M1 C.M3.
((I) ((A) c)). m2():- , C.M2.
Source: https://habr.com/ru/post/1732159/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1732154/javascript-adding-ellipsis-to-html-text-according-to-container-size&usg=ALkJrhiZ2-xxx2HX9Ow5m-9AABVpr7H0PAhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1732155/if-i-add-new-possible-values-to-my-enum-type-will-this-change-my-wsdl&usg=ALkJrhh05apbRnTiCF6dHl8iQV8cpMHSsQCan someone help me with installing the eclipse bugzilla plugin? - eclipseAdding instruction labels in edit mode UIpickerviewcontroller - iphoneLooking for tutorials on writing PHP modules? - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1732161/add-calculated-column-with-checkboxes-to-datagrid&usg=ALkJrhgz_CKjttYPT1s4KmsQRO-IAo70ZwDoes the assembly or exe sign a digital certificate, does it protect against fakes? - securityHow to declare a javascript class with short function names and assign a long class name later? - javascriptBuild Progress in Visual Studio - c #WINAPI to get device status - winapiAll Articles