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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:36:28+00:00 2026-06-13T16:36:28+00:00

I have a list: IList<PIData> list = new List<PIData>() This returns a list like

  • 0

I have a list:

IList<PIData> list = new List<PIData>()

This returns a list like this:

Timestamp        | End              | HeaderTitle | Value
=========================================================
12/12/2012 00:00 | 12/12/2012 00:01 | Test1       | 0.23
12/12/2012 00:00 | 12/12/2012 00:01 | Test2       | 0.34
12/12/2012 00:00 | 12/12/2012 00:01 | Test3       | 0.556

This continues on and on where sometimes I will have 50-100 different HeaderTitles

I need to be able to pivot this and ultimately write it to a CSV with Row being a header. I know how to convert an object to CSV but I am having a super hard time pivoting the list and hoping someone can help.

here is what I want to it to look like:

Timestamp        | End              | Test1 | Test2 | Test3 | etc
==================================================================
12/12/2012 00:00 | 12/12/2012 00:01 | 0.23  | 0.34  | 0.556
12/12/2012 00:01 | 12/12/2012 00:02 | 0.23  | 0.34  | 0.556
12/12/2012 00:02 | 12/12/2012 00:03 | 0.23  | 0.34  | 0.556

Can someone help me make this work? I really just need to be able to pivot my List to a new List that will ultimately be a CSV file… I know how to do it in SQL but I cannot use SQL in this scenario.

  • 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-06-13T16:36:29+00:00Added an answer on June 13, 2026 at 4:36 pm

    Here is what I ended up doing what worked for me:

    namespace ConsoleApplication3
    {
    class Program
    {
    
        internal class PiData
        {
            public string HeaderName { get; set; }
            public DateTime TimeStamp { get; set; }
            public DateTime End { get; set; }
            public double Value { get; set; }
        }
    
        static void Main(string[] args)
        {
            var PD = new List<PiData>()
            {
                new PiData() { HeaderName="Test1", End = DateTime.Now.AddSeconds(15), TimeStamp = DateTime.Now, Value = 0.01 },
                new PiData() { HeaderName="Testf2", End = DateTime.Now.AddSeconds(15), TimeStamp = DateTime.Now, Value = 0.51 },
                new PiData() { HeaderName="Testff3", End = DateTime.Now.AddSeconds(15), TimeStamp = DateTime.Now, Value = 0.71 },
                new PiData() { HeaderName="Testfsd4", End = DateTime.Now.AddSeconds(15), TimeStamp = DateTime.Now, Value = 0.41 },
                new PiData() { HeaderName="Test1", End = DateTime.Now.AddSeconds(30), TimeStamp = DateTime.Now.AddSeconds(15), Value = 0.01 },
                new PiData() { HeaderName="Testf2", End = DateTime.Now.AddSeconds(30), TimeStamp = DateTime.Now.AddSeconds(15), Value = 0.51 },
                new PiData() { HeaderName="Testff3", End = DateTime.Now.AddSeconds(30), TimeStamp = DateTime.Now.AddSeconds(15), Value = 0.71 },
                new PiData() { HeaderName="Testfsd4", End = DateTime.Now.AddSeconds(30), TimeStamp = DateTime.Now.AddSeconds(15), Value = 0.41 },
            };
    
    
        var result2 = PD.Pivot(emp => emp.TimeStamp, emp2 => emp2.HeaderName, lst => lst.Sum(a => a.Value));
        StringBuilder sb = new StringBuilder();
    
        List<string> columns = new List<string>();
        columns.Add("TimeStamp");
        columns.Add("End");
        foreach (var item in PD.Select(a => a.HeaderName).Distinct())
        {
            columns.Add(item);
        }
        foreach (var item in columns)
        {
            sb.Append(item + ",");
        }
        sb.Remove(sb.Length - 1, 1);
        sb.AppendLine();
        foreach (var row in result2)
        {
            sb.Append(row.Key + "," + row.Key.AddSeconds(10).ToString() + ",");
            foreach (var column in row.Value)
            {
                sb.Append(column.Value + ",");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.AppendLine();
        }
        Console.WriteLine(sb.ToString());
        Console.WriteLine("----"); 
    
        }
    }
    
    public static class LinqExtenions
    {
    
        public static Dictionary<TFirstKey, Dictionary<TSecondKey, TValue>> Pivot<TSource, TFirstKey, TSecondKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TFirstKey> firstKeySelector, Func<TSource, TSecondKey> secondKeySelector, Func<IEnumerable<TSource>, TValue> aggregate)
        {
            var retVal = new Dictionary<TFirstKey, Dictionary<TSecondKey, TValue>>();
    
            var l = source.ToLookup(firstKeySelector);
            foreach (var item in l)
            {
                var dict = new Dictionary<TSecondKey, TValue>();
                retVal.Add(item.Key, dict);
                var subdict = item.ToLookup(secondKeySelector);
                foreach (var subitem in subdict)
                {
                    dict.Add(subitem.Key, aggregate(subitem));
                }
            }
    
            return retVal;
        }
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this List<string> : IList<string> ListaServizi = new List<string>(); How can I order
Can anyone help.. I have a generic list like so IList<itemTp> itemTps; itemTp basically
I have an IList<MyList> . I'd like with LINQ keep the same list (same
i have list of items IList with data that looks list this: GenId TestMode
I have a generic list: IList<T> myobj = new List<T>(); how to check if
When i have a list IList<int> list = new List<int>(); list.Add(100); list.Add(200); list.Add(300); list.Add(400);
Assuming I have the following list: IList<string> list = new List<string>(); list.Add(Mouse); list.Add(Dinner); list.Add(House);
I have this list : IList<Modulo> moduli = (from Modulo module in Moduli select
I have these Extension methods: public static void Replace<T>(this IList list, T newItem) public
Suppose I have one list: IList<int> originalList = new List<int>(); originalList.add(1); originalList.add(5); originalList.add(10); And

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.