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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:04:12+00:00 2026-06-11T08:04:12+00:00

How to dynamically create objects? string[] columnNames = { EmpName, EmpID, PhoneNo }; List<string[]>

  • 0

How to dynamically create objects?

string[] columnNames = { "EmpName", "EmpID", "PhoneNo" };
List<string[]> columnValues = new List<string[]>();
for (int i = 0; i < 10; i++)
{
    columnValues.Add(new[] { "Ramesh", "12345", "12345" });
}

List<Dictionary<string, object>> testData = new List<Dictionary<string, object>>();

foreach (string[] columnValue in columnValues)
{
    Dictionary<string, object> data = new Dictionary<string, object>();
    for (int j = 0; j < columnNames.Count(); j++)
    {
        data.Add(columnNames[j], columnValues[j]);
    }
    testData.Add(data);
}

Imaginary Class(Class is not available in code):

class Employee
{
    string EmpName { get;set; }
    string EmpID { get;set; }
    string PhoneNo { get;set; }
}

Note: Property/column names are dynamic.

Now I want to convert the List<Dictionary<string, object>> to a class of type List<object> (i.e) List<Employee>.

Is it Possible? Suggestions please.

  • 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-11T08:04:14+00:00Added an answer on June 11, 2026 at 8:04 am

    Using an anonymous object (if you know the properties you want to project):

    var employees = 
        (from dict in testData 
            select new 
            { 
                EmpName = dict["EmpName"] as string, 
                EmpID= dict["EmpID"] as string, 
                PhoneNo=dict["PhoneNo"] as string 
            }).ToList();
    

    Or, using System.Dynamic.Expando (if you need to dynamically project unknown column names):

    string[] columnNames = { "EmpName", "EmpID", "PhoneNo" };
    List<string[]> columnValues = new List<string[]>();
    for (int i = 0; i < 10; i++)
    {
        columnValues.Add(new[] { "Ramesh", "12345", "12345" });
    }
    
    var testData = new List<ExpandoObject>();
    
    foreach (string[] columnValue in columnValues)
    {
        dynamic data = new ExpandoObject();
        for (int j = 0; j < columnNames.Count(); j++)
        {
            ((IDictionary<String,Object>)data).Add(columnNames[j], columnValue[j]);
        }
        testData.Add(data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create objects dynamically, using eval(string) . I've been unable to find
In the following example i can create an object dynamically via a string; however,
I know how to create simple object and add dynamically properties to it. object
Is there a way to dynamically create an object using a string as the
I have a need to store a list of dynamically created objects in a
Is there a (better) way to dynamically create Objects? Right now I'm using a
I'm trying to dynamically create domain objects in Grails and encountered the problem that
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I am currently trying to assign an event handler to dynamically created rectangle objects.
Am attempting to dynamically create html which then injects itself as an iframe into

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.