【发布时间】:2022-01-19 18:24:02
【问题描述】:
您好,我想创建一个数据集并使用我拥有的所有意大利名称的 txt 文件填充它,例如: 蕉
阿邦丹扎
阿凡达
阿布达齐奥
阿布达齐奥
阿邦迪亚
阿邦迪娜
没有空格。有没有简单的代码来做到这一点?谢谢。
【问题讨论】:
标签: c# asp.net dataset c#-datatable
您好,我想创建一个数据集并使用我拥有的所有意大利名称的 txt 文件填充它,例如: 蕉
阿邦丹扎
阿凡达
阿布达齐奥
阿布达齐奥
阿邦迪亚
阿邦迪娜
没有空格。有没有简单的代码来做到这一点?谢谢。
【问题讨论】:
标签: c# asp.net dataset c#-datatable
尝试以下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
string[] inputs = {"abaco","abbondanza","abbondanzia","abbondanzio","abbondazio","abbondia","abbondina"};
DataTable dt = new DataTable();
dt.Columns.Add("Italian Names", typeof(string));
foreach (string input in inputs)
{
dt.Rows.Add(new string[] { input });
}
}
}
}
更新
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("C:\\Users\\Fabio\\Desktop\\dataset\\nomi_italiani.txt"))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
listnamedataset = //HOW CAN I ADD EVERY ELEMENT TO THE LIST??
}
}
}
catch (Exception e)
{
}
【讨论】: