什么是C#等价的朋友? [英] What is the C# equivalent of friend?
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/203616/why-does-c-sharp-not-provide-the-c-style-friend-keyword\">Why没有C#不提供C ++风格的'朋友'的关键字?
我想一类的私有成员变量是可以访问到一个测试类,而不使他们暴露在其他类。
I'd like the private member variables of a class to be accessible to a Tester class without exposing them to other classes.
在C ++中我只是声明Tester类作为一个朋友,我该如何在C#这样做吗?有人可以给我一个例子吗?
In C++ I'd just declare the Tester class as a friend, how do I do this in C#? Can someone give me an example?
推荐答案
还有的朋友没有直接等同 - 这是提供的最接近的(而且不是很接近)是<一个href=\"http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx\">InternalsVisibleTo.我只用过这个属性测试 - 它是非常方便的。
There's no direct equivalent of "friend" - the closest that's available (and it isn't very close) is InternalsVisibleTo. I've only ever used this attribute for testing - where it's very handy!
这篇关于什么是C#等价的朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!