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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:01:59+00:00 2026-05-25T01:01:59+00:00

I am adding information to a dictionary using this code: foreach (string word in

  • 0

I am adding information to a dictionary using this code:

foreach (string word in lineList)
{
    if (dictionary.ContainsKey(word))
        dictionary[word]++;
    else
        dictionary[word] = 1;
}

// I believe this is what needs to change..?
var ordered = from k in dictionary.Keys select k;

When I use the StreamWriter to print out the lines it is printing it out in the order it was added to the dictionary.

What I am trying to do is print it out in an order that first compares the PartDescriptionand then the PartNumber and prints it out numerically.

the File looks like this:

PartDescription        PartNumber        Name        X        Y        Rotation
1608RTANT              147430            J1        20.555   -12.121       180
TANTD                  148966            J2        20.555   -12.121       270
SOMETHING              148966            R111      20.555   -12.121       360
SOMETHING              148966            C121      20.555   -12.121       180
SOMETHING              148966            R50       205.555  -12.121       180
SOMETHING              148966            R51      -205.555  125.121       270
SOMETHING              148966            R52       20.555   -12.121       0
SOMETHING              148966            C12       20.555   -12.121       0
1709RTANT              147430            C98       20.555   -12.121       0
1608RTANT              147429            QD1       20.555   -12.121       180
1709RTANT              147430            F12       20.555   -12.121       0
1609RTANT              147445            P9        20.555   -12.121       180

The StreamWriter would output like this:

1, 1608RTANT, 147429, 1   //Line#, PartDescription, PartNumber, # of Duplicates (from dictionary key)
2, 1608RTANT, 147430, 1
3, 1609RTANT, 147445, 1
4, 1709RTANT, 147430, 2
5, SOMETHING, 148966, 6
6, TANTD, 148966, 1
  • 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-05-25T01:01:59+00:00Added an answer on May 25, 2026 at 1:01 am

    Well you could certainly get the keys in an ordered way easily:

    var ordered = from k in dictionary.Keys orderby k select k;
    

    Or even more simply:

    var ordered = dictionary.Keys.OrderBy(x => x);
    

    Note that you shouldn’t rely on the dictionary storing the pairs in the order in which you added them – basically you shouldn’t assume any ordering out of the dictionary.

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

Sidebar

Related Questions

This relates to adding information in a Foreignkey field in the main admin screen.
I am adding musicCD information to a set. I have two different functions for
I'm adding a number of fields to a table that stores information on vessels
I have found a lot of information about adding form helper methods (see one
I'm adding in-app purchase on my application. I have a view that displays information
So I am trying to troubleshoot why adding an item to my dictionary causes
Adding file information to a program. /** * @Author: Kyle * @Date: 9-29-2010 *
UPDATE: Please see the updates below, as I'm adding more information to the bottom
We're adding extra login information to an existing database record on the order of
Where can I find information on adding a toolbar to IE like Snagit and

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.