小编s22*_*211的帖子

GetProperty 方法返回 null C# .Net

有人可以解释一下,为什么 System.Type 中的 GetProperty 方法对于声明为“内部”但适用于“公共”的属性返回 null。

internal class Test{      
  public string ALocal { get; set; }
  internal string SLocal { get; set; }}

var test = new Test();
var testType = test.GetType();

var aProp = testType.GetProperty("ALocal"); => returns string Type
var sProp = testType.GetProperty("SLocal"); => returns null
Run Code Online (Sandbox Code Playgroud)

我了解内部或公共修饰符之间的差异。

.net c# access-modifiers

2
推荐指数
1
解决办法
3507
查看次数

标签 统计

.net ×1

access-modifiers ×1

c# ×1