1: using System;
2:
3: namespace Override_New
4: {
5: class clsBase
6: {
7: public virtual void Virtual_Override()
8: {
9: Console.WriteLine("Virtual_Override - Base");
10: }
11: public virtual void Virtual_New()
12: {
13: Console.WriteLine("Virtual_New- Base");
14: }
15: public virtual void Virtual_Not_New_Not_Override()
16: {
17: Console.WriteLine("Virtual_Not_New_Not_Override- Base");
18:
19: }
20: public void Not_Virtual_Not_New()
21: {
22: Console.WriteLine("Not_Virtual_Not_New- Base");
23: }
24: public void Not_Virtual_New()
25: {
26: Console.WriteLine("Not_Virtual_Not_New- Base");
27: }
28: }
29: class clsDerived:clsBase
30: {
31: public override void Virtual_Override()
32: {
33: Console.WriteLine("Virtual_Override - Derived");
34: }
35: public new void Virtual_New()
36: {
37: Console.WriteLine("Virtual_New - Derived");
38: }
39: public void Virtual_Not_New_Not_Override()
40: {
41: Console.WriteLine("Virtual_Not_New_Not_Override- Derived");
42:
43: }
44:
45: public void Not_Virtual_Not_New()
46: {
47: Console.WriteLine("Not_Virtual_Not_New- Derived");
48: }
49: public new void Not_Virtual_New()
50: {
51: Console.WriteLine("Not_Virtual_Not_New- Derived");
52: }
53: }
54:
55:
56:
57: class clsTest
58: {
59: /// <summary>
60: /// Demonstrate the various options
61: /// for override / new / virtual
62: /// </summary>
63: [STAThread]
64: static void Main(string[] args)
65: {
66: clsBase b=new clsDerived();
67: b.Virtual_New();
68: b.Virtual_Override();
69: b.Virtual_Not_New_Not_Override();
70: b.Not_Virtual_New();
71: b.Not_Virtual_Not_New();
72: Console.ReadLine();
73:
74: }
75: }
76: }
TOATE DAU BASE- - cu exceptia celei care este virtuale si suprascrisa EXPLICIT cu override . Numai aceea da Derived ...
Interesant ...