首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从txt文件填充数据集

从txt文件填充数据集
EN

Stack Overflow用户
提问于 2021-12-16 16:54:28
回答 1查看 44关注 0票数 -1

嗨,我想要创建一个数据集,并用一个txt文件填充它,我已经用了所有的意大利名字,例如: abaco

阿邦丹

阿邦丹菌

阿邦丹齐奥

阿邦达齐奥

abbondia

阿班迪纳

没有空间。有一个简单的代码来完成它吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-12-16 17:10:05

尝试以下几个方面:

代码语言:javascript
复制
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 });
            }

 

        }
    }
}

更新

代码语言:javascript
复制
  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)
            {
 
            }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70382791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档