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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:40:32+00:00 2026-05-15T21:40:32+00:00

Dictionary<string,string> items = new Dictionary<string,string>(); IEnumerable<string> textvalues = from c in……//using linQ to query

  • 0
Dictionary<string,string> items = new Dictionary<string,string>();

IEnumerable<string> textvalues = from c in......//using linQ to query

string s = textvalues[items["book"]];

In this case the textvalues array will accept a integer value to return the string value.How can i get the item number , say “items” has 5 itemnames and “book” is at first position then i must get 0.So textvalues[items[“book”]] would be translated as textvalues[item[0]]

Ok i was trying to use OpenXML 2.0 to read Excel.The point here is there is no way i could specify a field name and get the value.
So i was trying to iterate the first row of a worksheet, add the values to a dictionary Dictionary fieldItems so that when i say fieldItems[“Status”] it would retrieve me the cell value based on the column number , in my case the column header name.ok here’s the code for it.

        Dictionary<string, int> headers = new Dictionary<string, int>();
        IEnumerable<string> ColumnHeaders = from cell in  (from row in worksheet.Descendants<Row>()
                                            where row.RowIndex == 1
                                            select row).First().Descendants<Cell>()
                                           where cell.CellValue != null
                                           select
                                             (cell.DataType != null
                                               && cell.DataType.HasValue
                                               && cell.DataType == CellValues.SharedString
                                             ? sharedString.ChildElements[
                                               int.Parse(cell.CellValue.InnerText)].InnerText
                                             : cell.CellValue.InnerText);


          int i=0;
        Parallel.ForEach(ColumnHeaders, x => { headers.Add(x,i++); }); 


 order.Number = textValues[headers["Number"]];
  • 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-15T21:40:33+00:00Added an answer on May 15, 2026 at 9:40 pm

    (Darn, I didn’t misread it after all, and there’s no edit history in the first five minutes.)

    Your question is somewhat confusingly presented… but it seems like you’re basically trying to find the “position” of an item within a dictionary. There’s no such concept in Dictionary<TKey, TValue>. You should regard it as a set of mappings from keys to values.

    Obviously when you iterate over the entries in that set of mappings they will come out in some order – but there’s no guarantee that it will bear any relation to the order in which the entries were added. If you use SortedDictionary<,> or SortedList<,> (both of which are really still dictionaries), you can get the entries in sorted key order… but it’s not clear whether that would be good enough for you.

    It’s also not clear what you’re really trying to achieve – you call textvalues an array in the text, but declare it as an IEnumerable<string> – and it looks like you’re then trying to use an indexer with a string parameter…

    EDIT: Okay, now the question has been edited, you’ve got a Dictionary<string, int> rather than a Dictionary<string, string>… so the whole thing makes more sense. Now it’s easy:

    order.Number = textValues.ElementAt(headers["Number"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does performance for reading/adding values from/to Dictionary(Of String, SomeReferenceType) depend on the number
I have the following decleration: private Dictionary<string, Dictionary<string, File>> listFiles = new Dictionary<string,Dictionary<string,File>>(); How
Something very basic seems to be escaping me. Dim foo As New Dictionary(Of String,
I am changing string array into dictionary collection. string str = When everybody is
I've a Dictionary Dictionary<string, List<string>> SampleDict = new Dictionary<string, List<string>>(); I need to fill
I have a dictionary object IDictionary<string, string> which only has the following items: Item1,
I need to remove multiple items from a Dictionary. A simple way to do
Is there a better way (specially using Linq) to return a List/IEnumerable of the
I'm trying to bind columns from two different tables in to gridview using Linq
I have a List of String like List<String> MyList=new List<String>{A,B}; and a Dictionary<String, Dictionary<String,String>>

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.