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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:01:54+00:00 2026-05-16T18:01:54+00:00

Basically, I have a collection of objects each implement a member of Type IValueCollection

  • 0

Basically, I have a collection of objects each implement a member of Type IValueCollection.

public interface IValueCollection : IEnumerable<decimal>
{
    decimal this[int index] { get; set; }
}

MeasurementCollection.Values is of type IValueCollection.

With the logic below I want to pivot a collection of IValueCollection and wrote the extension method below.

public static IEnumerable<IValueCollection> PivotValues(this MeasurementCollection items)
{
    if(items.IsQuantized())
    {
        int s = (int)items.First().Template.Frequency;
        int c = items.Count;
        for (int n = 0; n < s; n++)
        {
            IValueCollection v = new MeasurementValueCollection(c);
            for (int m = 0; m < c; m++)
                v[m] = items.ElementAt(m).Values[n];
            yield return v;
        }
    }
}

should do
{{1,2,3}{4,5,6}{7,8,9}} results in {{1,4,7},{2,5,8},{3,6,9}}
However I think there is some nicer, slimmer and more readable expression to do this
can somebody point me in the right direction?

edit
info about underlying classes

interface IValueCollection : IEnumerable<decimal>
class MeasurementCollection : ICollection<IMeasurement>

interface IMeasurement 
{
    IMeasurementTemplate Template { get; }        
    ......
}

interface IMeasurementTemplate
{
    .....
    MeasurementFrequency Frequency { get; }    
}
  • 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-16T18:01:54+00:00Added an answer on May 16, 2026 at 6:01 pm

    I would, personally, force the evaluation of your collection in advance, and use it as an array. Right now, each time you call ElementAt, you’re going to evaluate the IEnumerable<T> again, causing a lot of repeated searching.

    By forcing it to evaluate to an array in advance, you simplify the entire process. Something like:

    public static IEnumerable<IValueCollection> PivotValues(this MeasurementCollection items)
    {
        if(items.IsQuantized())
        {
            int elementLength = (int)items.First().Template.Frequency;
            var itemArray = items.ToArray();
            for (int n = 0; n < itemArray.Length; n++)
            {
                IValueCollection v = new MeasurementValueCollection(elementLength);
                for (int m = 0; m < elementLength; m++)
                {
                    v[m] = itemArray[m].Values[n];
                }
                yield return v;
            }
        }
        else
            yield break; // Handle the case where IsQuantized() returns false...
    }
    

    If you control MeasurementValueCollection, I would add a constructor which takes an IEnumerable<decimal> as input, as well. You could then do:

    public static IEnumerable<IValueCollection> PivotValues(this MeasurementCollection items)
    {
        if(items.IsQuantized())
        {
            var elements = Enumerable.Range(0, (int)items.First().Template.Frequency);
            var itemArray = items.ToArray();
    
            foreach(var element in elements)
                yield return new MeasurementValueCollection(
                                     itemArray.Select( 
                                       (item,index) => itemArray[index].Value[element]
                                     )
                                 );
        }
        else
            yield break; // Handle the case where IsQuantized() returns false...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically each entity would have a collection of feeding behaviors that it would follow.
I have this method called MatchNodes: IEnumerable<bool> MatchNodes<T>(T n1, T n2) Which basically gets
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have the same question as this guy .. The example in the
I have implemented a java program . This is basically a multi threaded service
I have a location class. This class basically holds addresses, hence the term location.
I have a list of objects. Each object has a property named ext that
Quite new to Linq, and I'm struggling with this one. Basically I have a
I have a Course class which contains collection of CourseItems . Each CourseItem has
I basically have a page which shows a processing screen which has been flushed

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.