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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:53:44+00:00 2026-05-17T23:53:44+00:00

i have an array of custom objects. i’d like to be able to reference

  • 0

i have an array of custom objects. i’d like to be able to reference this array by a particular data member, for instance myArrary["Item1"]

“Item1” is actually the value stored in the Name property of this custom type and I can write a predicate to mark the appropriate array item. However I am unclear as to how to let the array know i’d like to use this predicate to find the array item.

I’d like to just use a dictionary or hashtable or NameValuePair for this array, and get around this whole problem but it’s generated and it must remain as CustomObj[]. i’m also trying to avoid loading a dictionary from this array as it’s going to happen many times and there could be many objects in it.

For clarification

myArray[5] = new CustomObj() // easy!
myArray["ItemName"] = new CustomObj(); // how to do this? 

Can the above be done? I’m really just looking for something similar to how DataRow.Columns["MyColumnName"] works

Thanks for the advice.

  • 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-17T23:53:45+00:00Added an answer on May 17, 2026 at 11:53 pm

    What you really want is an OrderedDictionary. The version that .NET provides in System.Collections.Specialized is not generic – however there is a generic version on CodeProject that you could use. Internally, this is really just a hashtable married to a list … but it is exposed in a uniform manner.

    If you really want to avoid using a dictionary – you’re going to have to live with O(n) lookup performance for an item by key. In that case, stick with an array or list and just use the LINQ Where() method to lookup a value. You can use either First() or Single() depending on whether duplicate entries are expected.

    var myArrayOfCustom = ...
    var item = myArrayOfCustom.Where( x => x.Name = "yourSearchValue" ).First();
    

    It’s easy enough to wrap this functionality into a class so that external consumers are not burdened by this knowledge, and can use simple indexers to access the data. You could then add features like memoization if you expect the same values are going to be accessed frequently. In this way you could amortize the cost of building the underlying lookup dictionary over multiple accesses.

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

Sidebar

Related Questions

I have an array of custom objects. MyCustomArr[]. I want to convert this to
I have an array of custom objects. The objects includes a dictionary. Something like
I have a mutable array of custom objects. I want to filter that array
I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit
I have a method that returns an array of custom class objects that are
I have an array of a few million numbers. double* const data = new
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an array of numbers that potentially have up to 8 decimal places
I have an array of items that are time sensitive. After an amount of
I have an array of hashes, and I want the unique values out of

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.