Just trying to do something basic and am getting stuck. Want to initialize an observable collection in my model class (See code below) and cant seem to get it working. I have put in _ for the part which is not working.
Can somebody please provide pointers
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; }
}
I know I can do the traditional way (like below) but want to learn the above methodology
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}}
};
Look at the type on your inherited ObservableCollection:
This makes your type a collection of strings and lists, not strings and TickerDetails. Change your inherited type to string, TickerDetails and you’ll be able to initialize. However you’ll also need to change the signiture of getData() to match the new inherited signiture, or provide a transformation from TickerDetails to List, Int