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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:30:37+00:00 2026-05-31T10:30:37+00:00

Hello I have a little problem with assigning property values from one lists items

  • 0

Hello I have a little problem with assigning property values from one lists items to anothers. I know i could solve it “the old way” by iterating through both lists etc. but I am looking for more elegant solution using LINQ.

Let’s start with the code …

class SourceType
{
    public int Id;
    public string Name;
    // other properties
}

class DestinationType
{
    public int Id;
    public string Name;
    // other properties
}

List<SourceType> sourceList = new List<SourceType>();
sourceList.Add(new SourceType { Id = 1, Name = "1111" });
sourceList.Add(new SourceType { Id = 2, Name = "2222" });
sourceList.Add(new SourceType { Id = 3, Name = "3333" });
sourceList.Add(new SourceType { Id = 5, Name = "5555" });

List<DestinationType> destinationList = new List<DestinationType>();
destinationList.Add(new DestinationType { Id = 1, Name = null });
destinationList.Add(new DestinationType { Id = 2, Name = null });
destinationList.Add(new DestinationType { Id = 3, Name = null });
destinationList.Add(new DestinationType { Id = 4, Name = null });

I would like to achieve the following:

  • destinationList should be filled with Names of corresponding entries (by Id) in sourceList
  • destinationList should not contain entries that are not present in both lists at once (eg. Id: 4,5 should be eliminated) – something like inner join
  • I would like to avoid creating new destinationList with updated entries because both lists already exist and are very large,
    so no “convert” or “select new”.

In the end destinationList should contain:

1 "1111"
2 "2222"
3 "3333"

Is there some kind of elegant (one line Lambda? 😉 solution to this using LINQ ?

Any help will be greatly appreciated! Thanks!

  • 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-31T10:30:39+00:00Added an answer on May 31, 2026 at 10:30 am

    I would just build up a dictionary and use that:

    Dictionary<int, string> map = sourceList.ToDictionary(x => x.Id, x => x.Name);
    
    foreach (var item in destinationList)
        if (map.ContainsKey(item.Id))
            item.Name = map[item.Id];
    
    destinationList.RemoveAll(x=> x.Name == null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! I have a little problem I was hoping the community could help me
Hello I have a little problem with requests : In an action executeFiche, I
i have a little problem about preg_match_all and str_replace <? $source = 'hello @user_name,
Situation: Hello! I have a little problem in a C# project. I am using
Hello i'm practising C and i have a little problem with the following code.
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
Hello folkes I have this little problem for which I cannot find a suitable
Hello fellow developers, I am a little stumped on this one as I have
Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little
Going deeper in C#, I have encountered a little (strange) problem with object reference

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.