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

推荐订阅源

Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Martin Fowler
Martin Fowler
The Cloudflare Blog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
量子位
Vercel News
Vercel News
C
Check Point Blog
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
Schneier on Security
Schneier on Security
O
OpenAI News
M
MIT News - Artificial intelligence
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security Affairs
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
L
LINUX DO - 最新话题
The Last Watchdog
The Last Watchdog
C
CERT Recently Published Vulnerability Notes
aimingoo的专栏
aimingoo的专栏
V
V2EX
博客园 - 【当耐特】
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志

博客园 - KiddLee

数据库存储图像及使用Image控件显示 三层体系结构总结(六) Spring.Core IoC(一) Spring.Net 模块组成 Generating user instances in Sql Server is disabled. Use sp_configure 'user instances enabled' to generate user instances 面向对象分析设计学习与探索(六):好的设计=软件的灵活程度(good design=flexible software)继续 面向对象分析设计学习与探索(六):面向对象的灾难(OO Catastrophe) 面向对象分析设计学习与探索(六):好的设计=软件的灵活程度(good design=flexible software) 面向对象分析设计学习与探索(五):分析(Analysis) 面向对象分析设计学习与探索(四):需求变化(Requirements Change) 面向对象分析设计学习与探索(三):收集需求(Gathering Requirement) 面向对象分析设计学习与探索(二):好的应用程序设计(Well-designed apps rock) 面向对象分析设计学习与探索(一):开篇 类型构造器 装箱拆箱续 Session Cookie and Persistent Cookie 第一次执行方法 我犯错了 装箱拆箱
接口函数还可以声明为private
KiddLee · 2007-03-01 · via 博客园 - KiddLee

                以私有化方式实现接口中的函数,我是第一次听说,下面就来看看:

                首先声明一个接口:

        public interface ITest

    {

        void Test1();

        void Test2();

}

   接下来,我们再来实现接口

    public class Test : ITest

    {

        public void Test1()

        {

            Console.WriteLine("Test1");

        }

        void ITest.Test2()

        {

            Console.WriteLine("Test2");

        }

}

   注意:对于Test2方法是以这种方式来满足接口要求的

   我们再用客户端验证一下:

    class Program

    {

        static void Main(string[] args)

        {

            Test tt = new Test();

            tt.Test1();

            Console.Read();

        }

}

   但是如果我要调用ttTest2方法会发现:



       
实例化的对象已经看不见Test2方法了,那如果我们想调用Test2方法有如何解决呢?我们可以这样做:

        static void Main(string[] args)

        {

            ITest itt = new Test();

            itt.Test1();

            itt.Test2();

            Console.Read();

    }

   以接口对象的方式声明,产生实际对象,这样就可以看见Test2方法了,运行结果是:

Test1

Test2