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

  • Home
  • SEARCH
  • 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 6787201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:20:15+00:00 2026-05-26T17:20:15+00:00

The xml elements are variable depending on some conditional. I need to initialize an

  • 0

The xml elements are variable depending on some conditional. I need to initialize an instance with a different element, based on the value of some other element.

var result = (from name in names
   select new MyName
   {
      name.First  = name.Type = Fracais ? name.PreNom : name.First,
      name.Last 
   }

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-05-26T17:20:16+00:00Added an answer on May 26, 2026 at 5:20 pm

    What you have is almost right. I had to guess the enums and members as you don’t provide the other classes:

       var result = from name in names
                     select new Person()
                       {
                          First = name.Type == PersonType.Fracais ? name.PreNom : name.First,
                          Last = name.Last
                       };
    

    You can have pretty much any expression, including function calls, in a linq query, so testing values and mutating them on the fly is perfectly acceptable.

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

Sidebar

Related Questions

I've got some XML elements with a number attached as more are available. Such
I have a list of xml elements that i need to search for specific
I am adding elements to an XML file during installation using the XmlFile element:
I have XML like this: <assessment> <variables> <variable> <attributes> <variable_name value=FRED/> </attributes> </variable> </variables>
I need to completely remove elements, based on the contents of an attribute, using
Hi I need get array of elements (before - if exist) by xsl. xml
I need to set a variable @XMLOutput to the value of the subquery in
Is it possible to find an xml element by searching with the value of
I'm receiving an XML message with unknown variable name elements... that is, they are
I need to count the number of elements in an XML file that have

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.