为什么我不能公开一个实现的接口方法? [英] Why cant I expose an implemented interface method?

查看:97
本文介绍了为什么我不能公开一个实现的接口方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试一些n层架构,我真的想知道为什么这段代码不会编译......

I've been trying out some n-tier architecture and im really wondering why this code wont compile...

它说修饰符public对于这个项目。但为什么不呢?我需要能够从BLL对象访问项目IRepository.AddString(),但它不会让我公开....

It says the modifier public is not valid for this item. But why not? I need to be able to access the item IRepository.AddString() from a BLL object but it just wont let me make it public....

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            BLL myBLL = new BLL();

        }
    }

    interface IRepository<T>
    {
        void AddString();
    }

    interface IStringRepo : IRepository<string>
    {
        List<string> GetStrings();
    }

    public class BLL : IStringRepo
    {
        public List<string> FilterStrings()
        {
            return new List<string>() { "Hello", "World" };
        }

        public List<string> IStringRepo.GetStrings()
        {
            throw new NotImplementedException();
        }

        public void IRepository<string>.AddString()
        {
            throw new NotImplementedException();
        }
    }
}


推荐答案

这是一个 明确实施的成员,它始终是私有的。

That's an explicitly-implemented member, which is always private.

从声明中删除 IStringRepo。以创建一个普通的公共成员实现接口。

Remove IStringRepo. from the declaration to create a normal public member that also implements the interface.

这篇关于为什么我不能公开一个实现的接口方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆