Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:18:10+00:00 2026-06-01T20:18:10+00:00

Just trying to do something basic and am getting stuck. Want to initialize an

  • 0

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}}
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:18:11+00:00Added an answer on June 1, 2026 at 8:18 pm

    Look at the type on your inherited ObservableCollection:

    ObservableCollection<string, List<int>>
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do something pretty basic here. I just want to make the
just trying to test for equality in this piece of code, but getting a
I am trying to do something really basic on C but I keep getting
I don't know why this is erroring, but I'm just trying to add something
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas
I'm just barely getting into NodeJS a bit and have hit a snag trying
I'm just trying to make the basic Selenium2Example work with Firefox 4 using Maven
I'm new to Visual Studio, and I'm just trying to write code as efficiently
Im trying to get into some basic JavaFX game development and I'm getting confused
I'm just beginning to learn C++ and I'm trying to make Thread class that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.