C#, DataTable to ArrayList?

前端 未结 5 1743
感情败类
感情败类 2020-12-11 04:19

I have a datatable with few rows each row has few columns.
I want to create an arraylist that countain all row as a string
so each array item look like this {1

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 04:38

    Here is a solution that actually works.

    ArrayList rows = new ArrayList();
    
    foreach (DataRow dataRow in myDataTable.Rows)
        rows.Add(string.Join(";", dataRow.ItemArray.Select(item => item.ToString())));
    

    However, I feel I should point out that it is unwise to use the obsolete ArrayList. Use List instead, since the rows are strings:

    List rows = new List();
    

    The rest of the code is the same.

提交回复
热议问题