小编S D*_*mar的帖子

如何在常量c#中使用getproperty

我正在尝试使用选址值获取恒定值,但我无法实现这一点,你可以帮助我这样做吗

using System;
public static class Constants
{
    public static class HostServer
    {
        public static string ABC = "abc.com";
    }
    public static class WMS
    {
        public const string URL = "/create/user";
    }
}
public class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello World");
        var x = Constants.GetType().GetProperty("ABC").GetValue(Constants, null).ToString();
        Console.WriteLine(x);
    }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

.net c# visual-studio

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

标签 统计

.net ×1

c# ×1

visual-studio ×1