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

  • SEARCH
  • Home
  • 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 7810701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:52:54+00:00 2026-06-02T03:52:54+00:00

The requirements for my application are as follows. I need to store orders which

  • 0

The requirements for my application are as follows. I need to store orders which look like this:

  • Each order pertains to a specific stockcode(string) and has a price, volume and whether or not it is being bought or sold(boolean) associated with it.

  • I need to do several operations on all orders that pertain to a specific stock, for example get the sum of the volume of orders for stockcode “abc”.

  • I need to be able to add an order to the data structure

  • I need to be able to remove an order from the data structure

  • I need to be able to find out which order is offering the best price after an order is added or removed.

Here is what I am thinking so far:

public class Order : IComparable
{

   private string _StockCode;
   private bool _BidSide;
   private int _Volume;
   private decimal _Price;
   private int _ExchangeOrderId;

   public int CompareTo(Order other)
   {
        if (_BidSide != other.BidSide)
        {
            return _BidSide ? 1 : -1;
        }
        return decimal.Compare(_Price, other.Price);
   }
}

And then I would store the orders in a Dictionary<string, List<Order>>. Where each stock code would be a key in the dictionary pointing to a list of orders for that stock. I would also maintain Dictionary matching an order id to a stock code.

  • For adding a new order, I simply find the appropriate list of orders in the dictionary based on the current stock code, and insert the order. I would also add an entry in the orderstock dictionary matching the current order with the approrpriate list.

  • For finding the best price, I look up the order list in the dictionary for the current stock code, sort the list and print out the highest order.

  • Removing is tricky. I would first need to look up the appropriate list by stock code. I would then need to iterate through all the orders for that stock code and find the one that matches the current order id and remove it. This is obviously inefficient if there are a lot of orders for the current stock code. Is this the best way of storing this information?

  • 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-02T03:52:55+00:00Added an answer on June 2, 2026 at 3:52 am

    If you’re going to do this with a lot of data, put it in a database. This is not something you want to do in a class.

    However, if you are using a small set of data, you could do this in code using LINQ.

    I think you should make Order implement IEnumerable and then use a List<Order> to store your orders. Make StockCode a public property on the Order and then you can retrieve orders by using Linq:

    List<Order> orders = GetOrderList();
    
    var ibmOrders = from o in orders
        where o.StockCode == "IBM"
        select o;
    

    Removing items from the list is quite simple:

    List<Order> orders = GetOrderList();
    
    var orderToRemove = (from o in orders
      where o.ExchangeId == 1315
      select o).FirstOrDefault();
    
    if (orderToRemove != null) {
        orders.Remove(orderToRemove);
    }
    

    Finding by best price using Linq is quite nice:

    Order bestPricedOrder = (from o in orders 
            orderby Price 
            select o).FirstOrDefault(); 
    

    For more great LINQ tricks, see 101 LINQ Samples.

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

Sidebar

Related Questions

Requirements Project should contain 1 main application and some secondary sub applications (which uses
I plan to develop a web application for which I need to decide the
I would like to develop an application in which voice can be recorded &
I have one requirement in my android application in which I need to run
Suppose I am creating an Android application that's like an SMS app. The requirements
in some part of my application there is a structure of activities like this:
My requirements are as follows: Once the application starts the PostgreSQL service will be
As part of my application requirements, I have a limit of 30 characters for
Requirements: On a web page in our web application, we have a requirement to
What are the requirements and how would I go about implementing the Application Push

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.