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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:11:22+00:00 2026-05-30T15:11:22+00:00

[CrossPost From MSDN] I had a task that, I need to send a generic

  • 0

[CrossPost From MSDN]

I had a task that, I need to send a generic List to a method, where I need to iterate it and convert it to an Excel File. I already did this with Data Table, but with Generic list I am facing some problems (I don’t want to convert my generic list to Data Table). I will paste the code which helps me out for an answer.

I Had Two Generic Lists

            List<User>       objList = new List<User>();
            List<Student> objStudent = new List<Student>();

// I am adding some Item to List

            User obj = new User(1, "aaa");
            User obj1 = new User(2, "bbb");
            User obj2 = new User(3, "ccc");
            User obj3 = new User(4, "ddd");


            Student sobj = new Student(1, "aaa");
            Student sobj1 = new Student(2, "bbb");
            Student sobj2 = new Student(3, "ccc");
            Student sobj3 = new Student(4, "ddd");
            objList.Add(obj);ExportToExcel(objList);

To Export it to Excel , I am passing the lists to the below methods as

    public void ExportToExcel<T>(IEnumerable<T> list)
    {
        PropertyInfo[] piT = typeof(T).GetProperties();

        var Users = list.ToList();

        Type myType = (typeof(T));
    }

When I am passing my list to Ienumerable… I am not able to retrieve the data present in the List IEnumerable list. If I retrieve the data , then I can handle further. Could any one suggest me the better Idea?

  • 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-30T15:11:23+00:00Added an answer on May 30, 2026 at 3:11 pm

    If you need to access the values of all the properties on type T, you can use the PropertyInfo.GetValue method:

    public void ExportToExcel<T>(IEnumerable<T> items)
    {
        var properties = typeof(T).GetProperties();
    
        foreach(var item in items)
        {
            foreach(var property in properties)
            {
                var value = property.GetValue(item, null);
    
                // Do something else with the property's value
            }
        }
    }
    

    Edit in response to comment

    You indicated you might receive a single list or a list of lists. You can add another overload which takes the composed lists, then iterate through it and export each individual list:

    public void ExportToExcel<T>(IEnumerable<IEnumerable<T>> itemSets)
    {
        foreach(var itemSet in itemSets)
        {
            ExportToExcel(itemSet);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that processes data from bluetooth and send it to the
I had posted this question on MSDN Forum http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/f00e3406-354d-4f54-acce-7b7f0ad4c90f But I am not getting
(This is actually a crosspost from gamedev , but I thought you guys and
Ok In an android vebview I have a java method. Is it possible that
This is a cross-post from the Mozilla Crypto Dev ML. Hoping that someone on
...and what can I do with my RichTextArea after the onInitialize method has been
I would like to modify the glossaryentryfield so that it creates output depending on
How can I create a diagonal line from the lower left corner to the
I've got a custom built news page that can cross post articles to Facebook
I have a need to run a piece of code every 120 seconds. I

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.