一个非常简单的C#面试题
怎样实现对所有类可读但是在同一个assembly可写那?
答案:
同一个assembly
namespace ClassLibrary1
{
public class Class1
{
public string Name
{
get;
internal set;
}
}
public class Class2
{
public void GS()
{
Class1 cc = new Class1();
cc.Name = "Joe";
}
}
}
不同assembly
Error 1 Property or indexer 'ClassLibrary1.Class1.Name' cannot be assigned to -- it is read only