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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:43:54+00:00 2026-05-20T08:43:54+00:00

I have got a List<Problem> which I want to export to a column based

  • 0

I have got a List<Problem> which I want to export to a column based file format (excel in my case).

So for each data member of my Problem class there is a corresponding column in my file.

Each column has got a header (string) and a function which will get that the row-value from a class Problem object (which can be of type string, double or DateTime).

To define the relation from Problem object to column I use a class like this:

private class ExportColumn<T>
{
    public ExportColumn (string colHeader, Func<Probleme, T> colGetter)
    {
        header = colHeader;
        getValue = colGetter;
    }

    public string header;
    // This function will return the row value for that column for one problem
    public Func<Probleme, T> getValue; 
}

How can I define a list of many ExportColumns, to iterate over and extract all the row data for all problems?

Something like this (pseudocode):

private static string GetThema(Probleme problem)
{
    return problem.Thema;
}

private static double GetStatus(Probleme problem)
{
    return problem.Status + 100;
}

private static readonly List<ExportColumn> colList = new List<ExportColumn> 
{
    ("Thema", GetThema),
    ("Status", GetStatus)
    ...
};

foreach(ExportColumn col in colList)
{
    foreach(Problem problem in Probleme)
    {
        WriteToFile(col.header, col.getValue(problem))
    }
}

I’m pretty new to C#, so perhaps this is the wrong way to solve that issue. Basically I just want one place in my code, where I define all headers, the corresponding function which will extract the value from a problem in a typesafe way.

Thanks for any help!

EDIT: In C++ words: I would like a vector of class ExportColumn which contain a string and a function pointer to a getter method with that signature : T getValue(const Problem &problem)

  • 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-20T08:43:55+00:00Added an answer on May 20, 2026 at 8:43 am

    You can’t do that, if the supplied generic parameter changes. You will need to create the struct without generics:

    class ExportColumn
    {
        public ExportColumn (string colHeader, Func<Probleme, object> colGetter)
        {
            Header = colHeader;
            GetValue = colGetter;
        }
    
        public string Header {get; private set;}
        // This function will return the row value for that column for one problem
        public Func<Probleme, object> GetValue {get; private set;}
    }
    

    Instances of this struct can now be put into a List<ExportColumn>.
    You could initialize that list like so:

    List<ExportColumn> colList = new List<ExportColumn> 
    {
        new ExportColumn("Thema", p => p.Thema),
        new ExportColumn("Status", p => p.Status + 100)
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long list that of which a snippet looks something like this:
I have an overview list, with divs, and also each div has a pair,
I got a problem here, implementing a Sorted Doubly Linked List of first and
I have a problem with LINQ. I have a list of item and I
I have a large number of csv files that I want to read into
I've searched google and cannot find any answers to the particular problem. I have
Problem: user made some selection in the multi-selection listbox, then pressed a checkbox, and
I need to develop a template-like user control, which would accept any arbitrary content,
I am using JPA (Hibernate) to store an entity on a MySQL 5.0 server.

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.