Вы почти у цели. Пожалуйста, попробуйте это
using System;
using System.Data;
namespace CompareLinuxWithWindow
{
class Program
{
static void Main(string[] args)
{
DataTable dt= ConvertToDataTable(@"C:\Users\manchunl\Desktop\Sample.txt", 10);
DataTable dt2= ConvertToDataTable(@"C:\Users\manchunl\Desktop\Sample.txt2", 10);
//Add these lines
for(int i=0;i<dt.Rows.Count;i++) //looping through all rows including the column. change `i=1` if need to exclude the columns display
{
for (int j = 0; j < dt.Columns.Count; j++) //looping through all columns
{
Console.WriteLine(dt.Rows[i][j]); //display of the data
}
}
//End of change
//Added for 2nd txt file
for(int i=0;i<dt2.Rows.Count;i++) //looping through all rows including the column. change `i=1` if need to exclude the columns display
{
for (int j = 0; j < dt2.Columns.Count; j++) //looping through all columns
{
Console.WriteLine(dt2.Rows[i][j]); //display of the data
}
}
//End :: Added for 2nd txt file
Console.WriteLine("Press enter to exit.");
Console.Read();
}
public static DataTable ConvertToDataTable(string filePath, int numberOfColumns)
{
DataTable tbl = new DataTable();
for (int col = 0; col < numberOfColumns; col++)
tbl.Columns.Add(new DataColumn("Column" + (col + 1).ToString()));
string[] lines = System.IO.File.ReadAllLines(filePath);
foreach (string line in lines)
{
var cols = line.Split(',');
DataRow dr = tbl.NewRow();
for (int cIndex = 0; cIndex < numberOfColumns; cIndex++)//changed hardcoded value of 10 to numberOfColumns
{
dr[cIndex] = cols[cIndex];
}
tbl.Rows.Add(dr);
}
return tbl;
}
}
}
Пожалуйста, дайте мне знать, если это поможет.
Вы можете использовать метод ключа
. localStorage.key (index)
возвращает index
-й ключ (порядок определяется реализацией, но остается неизменным, пока вы не добавите или не удалите ключи).
for (var i = 0; i < localStorage.length; i++){
$('body').append(localStorage.getItem(localStorage.key(i)));
}
Если порядок имеет значение, вы можете сохранить массив, сериализованный в формате JSON:
localStorage.setItem("words", JSON.stringify(["Lorem", "Ipsum", "Dolor"]));
В черновике спецификации утверждается, что любой объект, поддерживающий структурированный клон , может быть значением. Но, похоже, это пока не поддерживается.
РЕДАКТИРОВАТЬ: Чтобы загрузить массив, добавьте к нему, затем сохраните:
var words = JSON.parse(localStorage.getItem("words"));
words.push("hello");
localStorage.setItem("words", JSON.stringify(words));
Мы можем циклично выполниться через него с JavaScript для/в Оператора точно так же, как любой другой Объект.
И мы будем использовать .getItem()
для доступа к значению каждого ключа (x).
for (x in localStorage){
console.log(localStorage.getItem(x));
}