本文介绍了保护课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我希望能够使一个类只在命名空间中可见,即 只有命名空间中的其他类才能访问对它来说。 我尝试过对它进行受保护的关键字。那是行不通的。 我已经尝试将它嵌套在我想要使用它的类中,这类编译 编译,除了一些我依赖课程的方法有 不一致的辅助功能: 这是一个例子...... 公共类文件夹 { class FolderChild { } public static FolderChild [] GetFolders() { } } 基本上,除了 文件夹及其方法之外,我不希望FolderChild对其他任何内容可见。我怎么能这样做? 谢谢。 祝你好运, Dave Colliver。 http://www.AshfieldFOCUS.com ~~ http://www.FOCUSPortals.com - 提供本地特许经营权 解决方案 你不能 - 在.NET中没有这样的访问级别。 - Jon Skeet - < sk *** @ pobox.com> http ://www.pobox.com/~skeet 博客: http:/ /www.msmvps.com/jon.skeet 如果回复小组,请不要给我发邮件 那么为什么返回FolderChild对象数组的静态方法 public?这意味着FolderChild必须对所有程序集可见。 将该方法设为私有,因为您的代码示例已经完成了让FolderChild仅对Folders类可见的 目标 - FolderChild 是一个私有的嵌套类。 - Dave Sexton http://davesexton.com/blog " David" < da ***************** @ revilloc.REMOVETHIS.comwrot e in message news:%2 ********* ******* @ TK2MSFTNGP03.phx.gbl ... 那么为什么返回FolderChild对象数组的静态方法 public?这意味着FolderChild必须对所有程序集可见。 将该方法设为私有,因为您的代码示例已经完成了让FolderChild仅对Folders类可见的 目标 - FolderChild 是一个私有的嵌套类。 - Dave Sexton http://davesexton.com/blog " David" < da ***************** @ revilloc.REMOVETHIS.comwrot e in message news:%2 ********* ******* @ TK2MSFTNGP03.phx.gbl ... Hi,I want to be able to make a class only visible within the namespace, i.e.only other classes within the namespace will have access to it.I have tried putting a protected keyword against it. That doesn''t work.I have tried nesting it inside the class where I want to use it, this sortof compiles, except some of my methods that rely on the class have"Inconsistent accessibility:"Here is an example...public class Folders{class FolderChild{}public static FolderChild[] GetFolders(){}}Basically, I don''t want FolderChild to be visible to anything else exceptFolders and its methods. How can I do that?Thanks.Best regards,Dave Colliver. http://www.AshfieldFOCUS.com~~ http://www.FOCUSPortals.com - Local franchises available 解决方案You can''t - there''s no such access level in .NET.--Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeetIf replying to the group, please do not mail me tooThen why is the static method that returns an array of FolderChild objectspublic? That means that FolderChild must be visible to all assemblies.Make the method private, since your code example already accomplishes yourgoal of having FolderChild only visible to the Folders class - FolderChildis a private, nested class.--Dave Sexton http://davesexton.com/blog"David" <da*****************@revilloc.REMOVETHIS.comwrot e in messagenews:%2****************@TK2MSFTNGP03.phx.gbl...Then why is the static method that returns an array of FolderChild objectspublic? That means that FolderChild must be visible to all assemblies.Make the method private, since your code example already accomplishes yourgoal of having FolderChild only visible to the Folders class - FolderChildis a private, nested class.--Dave Sexton http://davesexton.com/blog"David" <da*****************@revilloc.REMOVETHIS.comwrot e in messagenews:%2****************@TK2MSFTNGP03.phx.gbl... 这篇关于保护课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 04:00