惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - shuang

heart or house? Dos for -- by 随风 - shuang C--Pointer Raid -----asp web 报表 - shuang ----[创业指南]给海归技术创业兄弟的九个忠告 --设计模式--Hibernate about avast job desc 把INT转换成2进制等 使用接口改变已经装箱的值类型的字段 struct也有方法成员 virtual 集成资源文件 const -readonly- static readonly 脚本---用函数模拟类 csm2 ClientScriptManager html______1
private/实现有多个相同方法的接口
shuang · 2007-12-20 · via 博客园 - shuang

当我们在一个类型中用完全限定接口名来定义一个接口方法时,该方法将被认为是私有方法,---只在该类型中(内部)可以调用,----而不能使用类型本身的引用来调用它。
----但是,当我们将该类型的引用转型为一个接口时,该接口中定义的方法将可以被调用,这时它(用完全限定接口名来定义的接口方法)又成为一个公有方法。---所以,当将gp变量转型为一个IWindow时,IWindow.GetMenu方法将是唯一可以调用的方法。
编译器按照先“完全限定接口成员”后“非完全限定接口成员”

using System;
using System.Collections.Generic;
using System.Text;

namespace App1
{
    
public interface IWindow
    
{
        Object getMenu();
    }

    
public interface IRestaurant
    
{
        Object getMenu();
    }

    
public class GiuseppePizzaria : IWindow, IRestaurant
    
{

        
IWindow Members

        
IRestaurant Members

        
public Object getMenu()//该类型自身的getMenu方法,与接口无关
        {
            Console.WriteLine(
"I'm GiuseppePizzaria's public method!");
            
return "";
        }

    }

    
class Program
    
{
        
static void Main(string[] args)
        
{
            GiuseppePizzaria gp 
= new GiuseppePizzaria();
            
object menu;
            
//调用公有的getMenu方法.使用GiuseppePizzaria引用,
            
//完全限定接口方法将为私有方法,因此不可能被调用.
            menu = gp.getMenu();
            
//调用IWindow的getMenu方法。使用IWindow引用,
            
//因此只有IWindow的getMenu()方法被调用。
            menu = ((IWindow)gp).getMenu();
            
//调用IWindow的getMenu方法。使用IWindow引用,
            
//因此只有IWindow的getMenu()方法被调用。
            menu = ((IRestaurant)gp).getMenu();
            Console.Read();
        }

    }

}