如何从文本文件中读取并添加到数组中?

时间:2015-05-08 16:53:21

标签: c# arrays file-read

我目前正在创建一个测验,并且我正在尝试使用测验来读取我的文本文件中的数据,但是我看到如何让它显示数据时遇到了绊脚石?

我的文件夹:

Windows.Storage.StorageFolder QuestionsFolder =
    Windows.Storage.ApplicationData.Current.LocalFolder;

我的阵列:

String[] Questions = new String[10];

我的阅读问题异步功能:

async Task ReadQuestions()
{
    try
    {
        StorageFile sampleFile = await QuestionsFolder.GetFileAsync("ms-appx:///Assets/Questions/myFile.txt");
        String Questions = await FileIO.ReadTextAsync(sampleFile);

        // Data is contained
    }
    catch (Exception)
    {

    }
}

示例数据:

"questions_id","questions" 
1,"What is the correct element for Gold ?"
2,"What is the correct element for Hydrogen?"
3,"What is the correct element for Oxygen?

有关如何完成此操作的任何想法,以便将问题从文本文件加载到数组中?

1 个答案:

答案 0 :(得分:0)

string [] questions = File.ReadAllLines(“ms-appx:///Assets/Questions/myFile.txt”);