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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:03:08+00:00 2026-05-21T09:03:08+00:00

I have a collection of this object : public Class MyObject() { public int

  • 0

I have a collection of this object :

public Class MyObject()
{
    public int Id { get; set; }
    public int Code { get; set; }
    public string NL { get; set; }
    public string FR { get; set; }
    public string Value { get; set; }
}

I have this

IList<MyObject> listObject = new List<Object>();
bool res = MyMethod();

I’d like depending of the res result copy all the value of FR to Value and from NL to Value if res is false :

I try this :

var res = (from p in listObject select new { Id = p.Id, Value = ??????  });

the ?????? reprsent the code I don’t find 🙁

Any idea ?

Thanks,

UPDATE1
I made a more generic method :

  public void MyTest<T>(IList<T> list) where T : ILookup
    {

        bool res = MyMethod();
        var result = (from p in list select new { Id = p.Id, Value = res? p.FR : p.NL });
        return result;

    }

What is the return type ?

  • 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-21T09:03:09+00:00Added an answer on May 21, 2026 at 9:03 am

    A conditional or ternary operator will help here. An example of how it work is:

    var result = booleanExpression ? valueIfTrue : valueIfFalse;
    

    applied to your code it would look something like this:

    var copy = (from p in listObject select new { Id = p.Id, Value = res ? p.FR : p.NL}); 
    

    If you wish the result to be returnable from the method you will have to use a class with your select statement rather than createing an anonymous type:

    var copy = (from p in listObject select new MyObject { Id = p.Id, Value = res ? p.FR : p.NL}); 
    

    where MyObject has properties defined as Id and Value. You could then return it as

    IEnumerable<MyObject >.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this object : public class Person { public string FirstName { get;
If I have a simple object: class MyObject { public string MyValueProperty { get;
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I have an object model like this: class Car { public string Manufacturer; public
I have this class: private static class ClassA{ int id; String name; public ClassA(int
I have a collection of entities with an any-association, like this: public class CreatedLog
I'm trying to build an object that looks something like this: public class MyObject
I have a class that represents some business object, such as this: Public Class
I have a ComboBox bound to a collection of objects defined as this. public
let's say we have simple data class: public class Ex { public string Prop1

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.