廖志的专栏

人无近忧,必有远虑 [天道酬勤]

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            testClass2 mytest 
= new testClass2();

            mytest.setValue2(
100);

            mytest.PrintTxt();

            mytest.outTxt();

            Console.ReadLine();

        }

    }

}
class1: base class
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp
{
    
    
public delegate void mydelegate();
    
    
class testClass1
    
{
        
private int int1, int2;


        
public int _int1
        
{
            
set { int1 = value; }
            
get return int1; }
        }


        
public int _int2
        
{
            
set { int2 = value; }
            
get return int2; }
        
        }


        
private void outTxt()
        
{
            Console.WriteLine(
"int1's value is {0} ; int2's value is {1}", int1, int2);
        
        }


        
public void PrintTxt()
        
{
            outTxt();
        
        }


        
public void setValue(int d1)
        
{
            
this.int1 = this.int2 = d1;
        
        }


        
public testClass1()
        
{ }

        
public testClass1(int d)
        
{
            
this.int1 = d;
            
this.int2 = d;
        
        }


        
public testClass1(int d1, int d2)
        
{
            
this.int1 = d1;
            
this.int2 = d2;
        }


    }

}

class2: 继承类
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp
{
    
class testClass2:testClass1
    
{
        mydelegate thisdelegate 
= null;
        
        
public testClass2()
            : 
base(1213)
        
{
            thisdelegate 
= new mydelegate(outTxt);
            thisdelegate();
            thisdelegate 
= new mydelegate(outCustomTxt);
            thisdelegate();
        }


        
public void setValue2(int d1)
        
{
            
this.setValue(123);
        
        }

        
public void outTxt()
        
{
            
this.PrintTxt();
        }


        
public void outCustomTxt()
        
{
            Console.WriteLine(
"测试委托!");
        }

    }

}


打印结果:

int1's value is 12 ; int2's value is 13
测试委托!
int1's value is 123 ; int2's value is 123
int1's value is 123 ; int2's value is 123
posted on 2005-05-12 14:35  dotnet学习者  阅读(155)  评论(0)    收藏  举报