나는 아래에 만든 datatable 내가 datatable에서 모든 행의 셀 길이를 나열해야합니다. 내 결과는 "0"값을 포함해서는 안됩니다. 하지만 내 목록 : 19,19,19,19,19, 0.0.0.0..0.0 ..... 왜 그렇습니까? Array의 길이는 어떻게 볼 수 있습니까?어떻게 datatable의 전체 셀에서 배열을 채울 수 있습니까?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace DataTables
{
class Program
{
static void Main(string[] args)
{
DataTable table = GetTable();
int[] mySortedLists = new int[table.Rows.Count*table.Columns.Count];
foreach (DataColumn dc in table.Columns)
{
foreach (DataRow dr in table.Rows)
{
Console.WriteLine(dr[dc].ToString().Length);
}
Console.WriteLine("\t");
}
Console.WriteLine("--------------------------------------");
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Columns.Count; j++)
{
mySortedLists[i] += table.Rows[i][j].ToString().Length;
}
}
foreach (var mySortedList in mySortedLists)
{
Console.WriteLine(mySortedList.ToString() + "\n");
}
Console.ReadKey();
}
static DataTable GetTable()
{
//
// Here we create a DataTable with four columns.
//
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
//
// Here we add five DataRows.
//
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
return table;
}
}
}
제발 도와주세요!
없음은 내가 행의 셀 .... – Penguen