我有以下課程。在其生命周期中的任何時候都可以添加更多屬性
public class Foo
{
public string propertyA { get; set; }
public string propertyB { get; set; }
public string propertyC { get; set; }
}
我有一個“Foo”的實體,它填充了以下值
var myFoo = new Foo()
{
propertyA = "X valueA",
propertyB = "valueB",
propertyC = "X valueC",
};
我如何遞回地獲取屬性的計數(在本例中),其字串值中的值為“X”?
uj5u.com熱心網友回復:
X 的期望值是多少?
你可以用這樣的函式回圈它:
foreach (PropertyInfo propertyInfo in obj.GetType().GetProperties())
{
// do stuff here
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/448947.html
