C#10:命名空间范围的访问修饰符

发布于 2025-01-13 14:03:48 字数 614 浏览 3 评论 0原文

正如标题所示,我很想在 C# 中看到这一点。

namespace PrivateStuff; //note: filescope namespace here!

public class PartiallyVisibleOutside
{
   public int A;
   namespace int B;
}

public class Test
{ 
    public PartiallyVisibleOutside NC {get; private set;}

    public void DoSmth()
    { 
        NC.A = 100000 + NC.B;  //OKAY til now!
        Console.Write(NC.A);
    }
}

//
namespace OUTSIDE;

public class OutsideClass 
{
   public PartiallyVisibleOutside Test;

   void DoSmth()
   {
      Test.A = 100; //OKAY
      Test.B = 100; //Compiletime-Error!
   }
}

这样的事存在吗?或者我应该在 C# 上打开一个功能请求

As in the title, I would love to see this in C#.

namespace PrivateStuff; //note: filescope namespace here!

public class PartiallyVisibleOutside
{
   public int A;
   namespace int B;
}

public class Test
{ 
    public PartiallyVisibleOutside NC {get; private set;}

    public void DoSmth()
    { 
        NC.A = 100000 + NC.B;  //OKAY til now!
        Console.Write(NC.A);
    }
}

//
namespace OUTSIDE;

public class OutsideClass 
{
   public PartiallyVisibleOutside Test;

   void DoSmth()
   {
      Test.A = 100; //OKAY
      Test.B = 100; //Compiletime-Error!
   }
}

Does smth like this exist? Or shall i open up a feature-request at C#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2025-01-20 14:03:48

没有这样的功能,我认为在近功能中实现它是非常利基的事情。尽管您可以通过将 TestPartiallyVisibleOutside 移动到单独的项目(程序集)并将 B 标记为 内部

There is no such feature and I think it is very niche thing to be implemented in near feature. Though you can simulate it by moving Test and PartiallyVisibleOutside into separate project (assembly) and marking B as internal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文