gpt4 book ai didi

c# - 如何计算 C# 中的类属性?

转载 作者:行者123 更新时间:2023-11-30 21:29:20 25 4
gpt4 key购买 nike

如何统计这个DataSources类的属性?答案应该是'3'

public class DataSources
{
public int Id { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
}

最佳答案

您可以使用 System.Reflection 中的类调查类型元数据命名空间。在你的情况下 TypeInfo -class 是一种在获取有关属性的信息时可以帮助您的类。

using System.Linq;

typeof(DataSources).GetProperties().Count();

或者

typeof(DataSources).GetProperties().Length;

关于c# - 如何计算 C# 中的类属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55468043/

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