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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:16:06+00:00 2026-06-08T12:16:06+00:00

I have a list with a lot of objects List<MyObjects> – Im iterating through

  • 0

I have a list with a lot of objects List<MyObjects> – Im iterating through this list and reading the objects. Thats all fine. I just relized now, what it would be awesome if I could add 1 more special value to this List – not an Object, just 1 value of something (a string).

I could now create a class like

class Needless
{
  public List<MyObjects> MyList { get; set; }
  public string MyValue { get; set; }
}

but Im trying to avoid that. I just really need 1 string with an input every List<MyObjects> Any ideas?

  • 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-08T12:16:07+00:00Added an answer on June 8, 2026 at 12:16 pm

    Tuple<string, List<MyObject>> is an option. However, if you are going to use this pairing a lot, I would advise creating a custom class for it to be more explicit – either like you have done, or by deriving List<MyObject> and adding the string as a property.

    If you are working “in scope” you could always make anonymous types:

    var t = new { TheString = "", TheList = new List<MyObject>() };
    var list = t.TheList;
    var s = t.TheString;
    

    But this only really has benefit in the scope of a method. The compiler can give IntelliSense for this and it is strongly-typed at compile time.

    Or if you really want to go all out, use ExpandoObject from System.Dynamic:

    var expando = new ExpandoObject();
    expando.List = new List<MyObject>();
    expando.TheString = "";
    

    This is typed in-line without any IntelliSense support, and will invoke the DLR. ExpandoObject simply uses an IDictionary<string, object> under the hood, so…

    var dict = (IDictionary<string, object>)expando;
    

    …is valid.

    The last option is a little tongue-in-cheek. It’ll work, but the development experience against it isn’t ideal compared to other options. That said, we use ExpandoObject in our test code, but I can’t remember why. One can only hope the reasoning was sound, but it was likely a developer getting giddy with new toys…

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

Sidebar

Related Questions

i have a list named simple and all its objects are in the form
I have a userform with 6 list objects. All of the list objects have
Possible Duplicate: Natural Sort Order in C# I have a list with a lot
I have a page with a list of lot of Products from the database.
I have a list of objects. These objects have three variables, ID, Name, &
I have a list of objects and I want to sent it thought TCP
So I have a list of objects with a number of properties. Among these
I have quite a lot of classes declared, all of them are inheriting from
I have already read a lot of posts around this subject but I am
Lately, I've been writing a lot of code that looks like this: List<MyObject> myList

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.