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 8794841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:22+00:00 2026-06-13T23:18:22+00:00

I have loaded a txt comma delimited into multiple lists. For example static public

  • 0

I have loaded a txt comma delimited into multiple lists. For example

static public void File()    
{    
    var order_no = new List<String>();    
    var quantity = new List<String>();    
    order_no.Add(fields[0]);    
    quantity.Add(fields[1]);    
}       

Now what i am trying to is in a loop while the same order is found down the list and the quantity is null then update the quantity in the previous.

For example

order NO : 1 quantity: null

order NO : 5 quantity: 2

order no : 1 quantity: 1

what it should do is to update the quantity in the first value to 1.

How can i accomplish that?

  • 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-13T23:18:22+00:00Added an answer on June 13, 2026 at 11:18 pm

    Personally i would prefer a Dictionary<String, String> instead since these pairs belong logically together(one quantity per order). But ok…

    You could group by order_no and select only one not-null value(if any):

    var orderGroups = order_no
        .Select((order, index) => new { 
             order, index,
             quantity = quantity.ElementAtOrDefault(index)
         })
        .GroupBy(x => x.order)
        .Where(g => g.Count() > 1);
    foreach(var og in orderGroups)
    {
        var firstNotNull = og.FirstOrDefault(x => x.quantity != null);
        if (firstNotNull != null)
        {
            var allIndices = og.Select(x => x.index);
            foreach (int index in allIndices)
                quantity[index] = firstNotNull.quantity;
        }
    }
    

    If you don’t want the first not-null quantity but the highest one, change these lines:

    var firstNotNull = og.Where(x => x.quantity != null)
                         .OrderByDescending(x => int.Parse(x.quantity))
                         .FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have loaded a file into an array using ajax and after splitting it
I have a NSMutableArray which is loaded from a txt file. There are 5
I have loaded an xmi file with an uml diagram. As a result I
I have loaded an XML file using simplexml_load_file($filePath,'SimpleXMLElement', LIBXML_NOCDATA); And for most of the
I have a sizeable txt file (3.5 MB) structured like so: sweep#1 expanse#1 0.375
I have a page that has multiple select lists and when ever one of
I have the simplest class text: class Text { char* txt; public: Text(const char*);
I need to load a PHP file into a variable. Like include(); I have
I have the following code to read a .txt file and to put it
I have a 150MB txt file of server logs. Probably with PHP, I want

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.