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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:24:10+00:00 2026-05-14T00:24:10+00:00

I have 2 objects, both of which I want to convert to dictionarys. I

  • 0

I have 2 objects, both of which I want to convert to dictionarys. I use toDictionary<>().

The lambda expression for one object to get the key is (i => i.name). For the other, it’s (i => i.inner.name). In the second one, i.name doesn’t exist. i.inner.name ALWAYS exists if i.name doesn’t.

Is there a lambda expression I can use to combine these two? Basically to read as:

“if i.name exists then set id to i.name, else set id to i.inner.name”.

Many thanks.

Update

When I say “don’t exist”, I mean the objects don’t actually have the properties, not that the properties are just null.

  • 1 1 Answer
  • 1 View
  • 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-14T00:24:10+00:00Added an answer on May 14, 2026 at 12:24 am

    Why don’t you give each object a ToDictionary method of their own, as they obviously have their own behaviours in this case.

    If you can’t add to the objects, because you don’t own them, you can always write extension methods for them.

    Any reason your trying to force feed them into one “common” function?

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

Sidebar

Related Questions

If I have a vector of objects in one class which I want to
I have two identically-sized numpy.array objects (both one-dimensional), one of which contains a list
I have an array of objects which I want to sort based on one
I have Class and Student objects. Both have collection of another as property. Which
I have two UIImageView objects inside my view (both 320x480 one above the other).
I currently have a JApplet within which I add two objects that both extend
I have two views which will both use the same Controller method: //webServiceController.cs //The
I have a multimap with Note objects from which I want to remove only
I have an Array of Objects which I want to filter depending on some
I have a time datetime object.. which has both date and time.. so for

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.