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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:09:26+00:00 2026-06-09T02:09:26+00:00

In my below function…I want to return DataTable.. Should I convert the below line

  • 0

In my below function…I want to return DataTable..

Should I convert the below line

DataTable table = CreateTable<T>();

to following

using(DataTable table = CreateTable<T>())
{
}

Function

public static DataTable ConvertTo<T>(IList<T> list)
{
    DataTable table = CreateTable<T>();

    int iColCount = table.Columns.Count;
    for (int j = 0; j < iColCount; j++)
    {
        DataColumn myDC = table.Columns[j];
        myDC.DataType = System.Type.GetType("System.String");
    }

    Type entityType = typeof(T);
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);
    foreach (T item in list)
    {
        DataRow row = table.NewRow();
        foreach (PropertyDescriptor prop in properties)
        {
            row[prop.Name] = prop.GetValue(item);
        } table.Rows.Add(row);
    }
    return table;
}
  • 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-09T02:09:28+00:00Added an answer on June 9, 2026 at 2:09 am

    Why would you?

    using (obj)
    {
        // Do something
    }
    

    is basically the same as:

    try
    {
        // Do something
    }
    finally
    {
        obj.Dispose();
    }
    

    The point is to free the resources used by your object once you don’t need it anymore. In your case, you’re returning the datatable to the calling function, so you’re still going to need it. Therefore, there’s no reason to wrap your function inside of a using statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to implement next previous functionality using below function. - (void)motionEnded:(UIEventSubtype)mt withEvent:(UIEvent *)event
I am using the below function in Java to convert an encrypted String into
I have the below function public static List<DateTime> GetOnlyFridays(DateTime endDate, int weeks, bool isIncludeBaseDate)
I have the below function public object Convert(object value) { string retVal = string.Empty;
Let's say we have the following JavaScript/jQuery code below function createElement(i, value) { return
I am using the below function of javascript to enable and disable the radio
Anyone experienced exception using below function? tdse.GetObject(tmpFolderWebDavURL, EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll) as Folder; Seems if
I am using Serial port to receive the messages. The below function is running
I am using below function to make a image of current form and set
I am using the below function to close the existing form and open a

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.