【发布时间】:2019-09-16 20:31:22
【问题描述】:
我想编写一个简单的代码来获取用户输入并从一个类中获取它。由于类中的大量对象我不想使用 if 或 switch,告诉我我该怎么做就像下面的代码或向我建议一个简单的代码,当我使用这个代码时它告诉我标识符预期
public class Rates
{
public double IRR { get; set; }
public double ISK { get; set; }
public double JEP { get; set; }
public double JMD { get; set; }//my object are more
public double JOD { get; set; }
public double JPY { get; set; }
public double KES { get; set; }
public double KGS { get; set; }
public double ZWL { get; set; }
}
public class RootObject_1
{
public string disclaimer { get; set; }
public string license { get; set; }
public int timestamp { get; set; }
public string @base { get; set; }
public Rates Rate { get; set; }
}
public void Main(string args)
{
string json_mosavab = (new WebClient()).DownloadString("my link");
var root1 = JsonConvert.DeserializeObject<RootObject_1>(json_mosavab);
string a = "IRR";//For example, the user input is IRR
Console.WriteLine("IRR IS :" + root1.Rate.(a));//MY error is here
//I wantmy code to work this way
Console.WriteLine("IRR IS :" + root1.Rate.IRR);
}
【问题讨论】:
标签: c# class object variables syntax