我有一个班级
public class GetRate : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string StockName;
private decimal? VolumeOrdered;
private decimal? BuyRate;
private decimal? SellRate;
private DateTime? OrderedDate;
}
另一个用webservice初始化它的类。
private static void Parse(List<GetRate> rates, XDocument doc)
{
XElement results = doc.Root.Element("results");
foreach (GetRate getRate in rates)
{
XElement q = results.Elements("rate").First(w=>w.Attribute"StockName").Value==rates.Symbol);
rates. VolumeOrdered = GetDecimal(q.Element("VolumeOrdered").Value);
rates. BuyRate = GetDecimal(q.Element("BuyRate").Value);
rates. SellRate = GetDecimal(q.Element("SellRate").Value);
rates.LastUpdate = DateTime.Now;
}
}
现在我想在另一个类中使用它的值。怎么可能? 我想用
class ABC
{
VolumeOrdered* BuyRate;
//Or
VolumeOrdered* SellRate;
}
需要帮助...... 在此先感谢...
答案 0 :(得分:4)
您需要在其他类中可见的其他类中创建要访问的变量:
public class GetRate : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string StockName;
private decimal? VolumeOrdered;
public decimal? BuyRate;
public decimal? SellRate;
private DateTime? OrderedDate;
}
更好的是,你应该使用getter和setter:
public class GetRate : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string StockName;
private decimal? VolumeOrdered;
public decimal? BuyRate { get; set; }
public decimal? SellRate { get; set; }
private DateTime? OrderedDate;
}