博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

5显式接口实现.avi

Posted on 2010-10-15 23:04  EVON168  阅读(255)  评论(0编辑  收藏  举报
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DisplayRealize
{
    
public interface Istudentplayable
    {
        
void Play();
    }

    
public interface IBoyFriendable
    {
        
void Play();
    }

    
public class Student : Istudentplayable, IBoyFriendable
    {


        
//显示接口主要为了防止方法名重名的时候,做到更加明细是哪个接口
        void Istudentplayable.Play()
        {
            Console.WriteLine(
"陪同学玩游戏!");
        }

        
void IBoyFriendable.Play()
        {
            Console.WriteLine(
"陪女朋友看电影!");
        }
    }

    
class Program
    {
        
static void Main(string[] args)
        {
            Student stu 
= new Student();

            Istudentplayable stuplay 
= stu;
            stuplay.Play();

            IBoyFriendable boyplay 
= stu;
            boyplay.Play();
        }
    }
}