只是试图做一些基本的事情并且我被卡住了。想要在我的模型类中初始化一个可观察的集合(参见下面的代码)并且似乎无法让它工作。我已经为不工作的部分添加了_ 。
有人可以提供指点吗
public class StockModel : ObservableCollection<KeyValuePair<string, TickerDetails>>
{
#region Properties
public string TickerSymbol { get; set; }
public TickerDetails Ticker { get; set; }
#endregion
public StockModel()
{
init();
}
public void init()
{
Add(new KeyValuePair<string, TickerDetails> { "ABC", new TickerDetails {TickerName="ABC", LastPrice=30, Ask=40, Bid=50, Volume=60 }});
}
public ObservableCollection<KeyValuePair<string, TickerDetails>> getData()
{
return this;
}
}
public class TickerDetails
{
public string TickerName { get; set; }
public int LastPrice { get; set; }
public int Bid { get; set; }
public int Ask { get; set; }
public int Volume { get; set; }
}
我知道我可以采用传统方式(如下所示)但想学习上述方法
Dictionary<int, StudentName> students = new Dictionary<int, StudentName>()
{
{ 111, new StudentName {FirstName="Sachin", LastName="Karnik", ID=211}},
{ 112, new StudentName {FirstName="Dina", LastName="Salimzianova", ID=317}},
{ 113, new StudentName {FirstName="Andy", LastName="Ruth", ID=198}}
};