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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:25:22+00:00 2026-05-18T20:25:22+00:00

I have 2 IEnumerables IEnumerable<float> Distance IEnumerable<XElement> Point which i want to convert into

  • 0

I have 2 IEnumerables

IEnumerable<float> Distance
IEnumerable<XElement> Point

which i want to convert into

IEnumerable<Subsection> subsection

where the Class is

class Subsection
{
    public float Distance
    public XElement Point
}

But i have no idea how to do this, i have tried some variations of casting none of which has worked because they dont seem to accept multiple lists as inputs.

The Distance and Point variables are read from a xml document where the structure for these two points is similar to:

<PLI>
    <Distance>5</Distance>
    <Point>23 22</Point>
    <Distance>7</Distance>
    <Point>21 72</Point>
    <Distance>9</Distance>
    <Point>13 32</Point>
</PLI>

I wasn’t sure how to read them out simply as the subsection type but if anyone could suggest how to do that, it would bypass my need to convert it as i will no longer have them as IEnumerables of distance and point but as the structure.

Please note I cannot modify the XML

Thanks

EDIT: The XML has other elements as well as the ones mentioned within the PLI Tag e.g.

<PLI>
    <OtherElement1>element1value</OtherElement1>
    <OtherElement2>element2value</OtherElement2>
    <Distance>5</Distance>
    <Point>23 22</Point>
    <Distance>7</Distance>
    <Point>21 72</Point>
    <Distance>9</Distance>
    <Point>13 32</Point>
</PLI>
  • 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-18T20:25:23+00:00Added an answer on May 18, 2026 at 8:25 pm

    You can pull this off with LINQ with the help of the Enumerable.Zip method, provided your XML is balanced (an even number of elements to pair up distances and points).

    var query = xml.Elements("Distance")
                   .Zip(xml.Elements("Point"),
                        (d, p) => new Subsection
                        {
                            Distance = float.Parse(d.Value),
                            Point = p
                        });
    

    Alternately, you could loop through the elements and build up the Subsection items. This can be done as follows, although it assumes your XML document is balanced and in the expected format.

    var query = xml.Elements()
                   .Where(e => e.Name.LocalName == "Distance"
                               || e.Name.LocalName == "Point");
    var list = new List<Subsection>();
    int count = 0;
    Subsection s = null;
    foreach (var element in query)
    {
        if (count % 2 == 0)
            s = new Subsection { Distance = float.Parse(element.Value) };
        else
        {
            s.Point = element;
            list.Add(s);
        }
    
        count++;
    }
    

    Note that in both snippets the xml variable is an XElement. For an XDocument add the Root property, as in xml.Root.Elements(...).

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

Sidebar

Related Questions

I have a class A { public float Score; ... } and an IEnumerable<A>
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
If I have an enumeration of dictionaries IEnumerable<IDictionary<string, float>> enumeration can I perform a
I'm currently trying to create a class which implements IEnumerable<T> in order to construct
I have a structure that looks following Class TreeNode { public TreeNode Parent {
I have a IEnumerable<T> collection with Name, FullName and Address. The Address looks like
I'm a newbie when it comes to LINQ... I have an IEnumerable generic list
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
Imagine I have the following: private IEnumerable MyFunc(parameter a) { using(MyDataContext dc = new
Does dot net have an interface like IEnumerable with a count property? I know

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.