Click here to Skip to main content
12,626,014 members (27,100 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
DataTable[] Mydt = new DataTable();
and fill it like :

Mydt[i] = .....
Do you know if such a syntax exist in c# ?

Posted 2-Jan-13 21:31pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can define array of table like this
DataTable[] tableArray = new DataTable[10]; // define DataTable array of Size 10

for(int i=0;i<10;i++)
 tableArray[i] = new DataTable();//create new data Table 
Suvabrata Roy 3-Jan-13 3:58am
jibesh you are absolutely right but if you use dataset rather that array I think it would me better.

jibesh 3-Jan-13 4:02am
Yes. That's another way of doing it. If I want array of table I usually do not prefer DataSet to avoid the other overheads, unless it requires operations supported by dataset
Suvabrata Roy 3-Jan-13 4:06am
Exactly :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


you can use from following code for create dynamic size of Data Table.
in this example you can get size of data table from user by console and create your DataTable and if user enter zero this while loop will be finished.

DataTable[] table;
int n;
while (true)
    Console.Write("Please enter size of Data Table: ");
    n = int.Parse(Console.ReadLine());
    if (n == 0)
    table = new DataTable[n];

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161205.3 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100