gpt4 book ai didi

C# - 通过公共(public)属性使私有(private)嵌套类可见

转载 作者:太空宇宙 更新时间:2023-11-03 17:38:07 51 4
gpt4 key购买 nike

<分区>

我有以下无法编译的代码:

public class Outer
{
public Inner MyField = new Inner(); //error here: "field type is less accessible than field"
private class Inner
{
public string Message = "Hello";
}
}

我必须能够像这样使用类:

var MyObject = new Outer();
Console.WriteLine(MyObject.MyField.Message); //should output "Hello"

“内部”必须可以从“外部”中实例化,所以这应该被允许:

var MyObject = new Outer.Inner(); //I do not want users to be able to instantiate "Inner" directly

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com