不用编辑器,回复你的答案~~
到处闲逛,看到两个前年的帖子,还真琢磨了一会的~~发上来给大家品品~~
要求:不用编辑器,回复你的答案,不带赖皮的哇~~
第一部分
1.
using System; class A { public virtual void Foo() { Console.WriteLine("Call on A.Foo()"); } } class B : A { public virtual void Foo() { Console.WriteLine("Call on B.Foo()"); } } class C : B { public override void Foo() { Console.WriteLine("Call on C.Foo()"); } } class D { static void Main() { A c1 = new C(); c1.Foo(); Console.ReadLine(); } }
using System; class A { public virtual void Foo() { Console.WriteLine("Call on A.Foo()"); } } class B : A { public override void Foo() { Console.WriteLine("Call on B.Foo() " ); } } class C : B { public new void Foo() { Console.WriteLine("Call on C.Foo()"); } } class D { static void Main() { A c1 = new C(); c1.Foo(); Console.ReadLine(); } }
using System; class A { public virtual void Foo() { Console.WriteLine("Call on A.Foo()"); } } class B : A { public virtual new void Foo() { Console.WriteLine("Call on B.Foo() " ); } } class C : B { public override void Foo() { Console.WriteLine("Call on C.Foo()"); } } class D { static void Main() { A c1 = new C(); c1.Foo(); Console.ReadLine(); } }
interface IGrandFather { void F(); } class Father:IGrandFather { public void F() { Console.WriteLine("\nFather."); } } class Children:Father { public new void F() { Console.WriteLine("\nChildren."); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
interface IGrandFather { void F(); } class Father:IGrandFather { public virtual void F() { Console.WriteLine("\nFather."); } } class Children:Father { public override void F() { Console.WriteLine("\nChildren."); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
interface IGrandFather { void F(); } class Father:IGrandFather { public virtual void F() { Console.WriteLine("\nFather."); } } class Children:Father { public void F(string arg) { Console.WriteLine("\nChildren:{0}",arg); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
interface IGrandFather { void F(); } abstract class Father:IGrandFather { public void F() { Console.WriteLine("\nFather."); } } class Children:Father { public void F() { Console.WriteLine("\nChildren."); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
interface IGrandFather { void F(); } abstract class Father:IGrandFather { public virtual void F() { Console.WriteLine("\nFather."); } } class Children:Father { public void F() { Console.WriteLine("\nChildren:{0}"); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); Console.ReadLine(); } }
interface GrandFather { void F(); } class Father:GrandFather { public void F() { Console.WriteLine("\nFather."); } } class Children:Father,GrandFather { public new void F() { Console.WriteLine("\nChildren"); } } class Test { public static void Main(string[] args) { GrandFather gf = new Children(); gf.F(); Console.ReadLine(); } }
using System; class A { public virtual void F(string p) { Console.WriteLine(p); } } class B:A { public void F(ref string p) { Console.WriteLine("ref:"+p); } } class Test { public static void Main(string[] args) { string s = "xxxx"; B b = new B(); b.F(s); b.F(ref s); } }