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

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator 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();
        }

    }

}