许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

接口


using System;

namespace testInterface
{
    
public interface  IAnimal    //必须是public或者internal
    {//要不要加访问修饰符? 不要
        string show();
        
string xianshi();
        
double Width{get;set;}
    }


    
class Dog:IAnimal
    
{
        
public string show() //此处必须是public,internal都不可以
        {
            
return "Dog Move,here and there:width=" + width;
        }

        
string IAnimal.xianshi()
        
{
            
return("若是显式实现,不得使用任何访问修饰符");
        }

        
//实现属性Property
        double width=0;
        
public double Width
        
{
            
get
            
{
                    
return width;
            }

            
set
            
{
                width 
= value;
            }

        }

    }


    
class myApp
    
{
        
static void Main_89() //
        {
            Dog d 
= new Dog();
            d.Width
=50;
            Console.WriteLine(d.show());
        }

    }

}


/*
 * 声明接口必须是internal或者public; protected和private不可以
 * 接口成员在声明时不得使用任何访问修饰符
 * 接口成员在类中被实现时:
 *        1.若是显式实现,不得使用任何访问修饰符
 *        2.若非显示实现,必须用public,internal都不可以
 * 
*/

posted on 2007-11-30 15:33  许明会  阅读(109)  评论(0)    收藏  举报