基本关键字

编程入门 行业动态 更新时间:2024-10-11 09:21:42
本文介绍了基本关键字 - 帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个实现接口的基类(空中代码): class BaseClass:SomeInterface { void SomeInterface.ImplMethod() { // - 此处代码 - } } 类派生:SomeInterface { void SomeInterface.ImplMethod() { //需要在此处调用基础实现 // - 此处代码 - } } 如果不公开实现,有办法吗? TIA Krishnan

Hi, Am having a base class that implements an interface (air code) : class BaseClass : SomeInterface { void SomeInterface.ImplMethod() { // -- code here -- } } class Derived : SomeInterface { void SomeInterface.ImplMethod() { //NEED TO CALL BASE''S IMPLEMENTATION HERE // -- code here -- } } Without making the implementations public, is there a way to do it? TIA Krishnan

推荐答案

> class BaseClass:SomeInterface > class BaseClass : SomeInterface class Derived:SomeInterface class Derived : SomeInterface

派生类不会从基类继承吗? 但是,即使继承,我也找不到一种方法来调用基础 类接口函数。也许其他人知道怎么做? 我只是通过将代码移动到辅助函数来找到解决办法。 像这样: 界面SomeInterface { void ImplMethod(); } 类BaseClass:SomeInterface { protected void方法(){/ *代码在这里* /} void SomeInterface.ImplMethod(){Method()} } class派生:BaseClass,SomeInterface { void SomeInterface.ImplMethod(){base.Method(); } } 问候, Wessel

The derived class doesn''t inherit from the base class? However, even when inheriting, I couldn''t find a way to call the base class interface function. Maybe someone else knows how to do it? I only found this work-around, by moving the code to a helper function. Like this: interface SomeInterface { void ImplMethod(); } class BaseClass : SomeInterface { protected void Method() { /* Code goes here */ } void SomeInterface.ImplMethod() { Method() } } class Derived : BaseClass, SomeInterface { void SomeInterface.ImplMethod() { base.Method(); } } Greetings, Wessel

>没有公开实现,有没有办法实现呢? 你的命名有点令人困惑,因为Derived不是来自 BaseClass。但是你可以做到 SomeInterface si = new BaseClass(); si.ImplMethod(); 如果这就是你想要的。 Mattias - Mattias Sj?gren [MVP ] mattias @ mvps www.msjogren/dotnet / | www.dotnetinterop 请回复到新闻组。 >Without making the implementations public, is there a way to do it? Your naming is a bit confusing since Derived doen''t derive from BaseClass. But you can do SomeInterface si = new BaseClass(); si.ImplMethod(); if that''s what you want. Mattias -- Mattias Sj?gren [MVP] mattias @ mvps www.msjogren/dotnet/ | www.dotnetinterop Please reply only to the newsgroup.

如果两个类都在同一个程序集中,你可以将方法设为内部 或者你真的派生自那个类并制作受保护的方法。 " Krishnan" < KR ********************* @ myrealbox> schrieb im Newsbeitrag 新闻:eO ************** @ tk2msftngp13.phx.gbl ... You could make the method internal if both classes are in the same assembly or you really derive from that class and make the method protected. "Krishnan" <kr*********************@myrealbox> schrieb im Newsbeitrag news:eO**************@tk2msftngp13.phx.gbl... 我有一个实现接口的基类(空中代码): 类BaseClass:SomeInterface { void SomeInterface.ImplMethod() { // - 这里的代码 - } 类派生:SomeInterface { void SomeInterface.ImplMethod() { //需要在这里打电话给基地的实施 // - 这里的代码 - } } 没有实现公众,有办法吗? TIA Krishnan Hi, Am having a base class that implements an interface (air code) : class BaseClass : SomeInterface { void SomeInterface.ImplMethod() { // -- code here -- } } class Derived : SomeInterface { void SomeInterface.ImplMethod() { //NEED TO CALL BASE''S IMPLEMENTATION HERE // -- code here -- } } Without making the implementations public, is there a way to do it? TIA Krishnan

更多推荐

基本关键字

本文发布于:2023-11-12 11:10:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关键字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!