C#无法将“字符串”转换为“System.Collections.Generic.IEnumerable<string>

c#

我是 C# 新手,我该如何解决这个问题?错误显示在最后一行(查询)。任何帮助表示赞赏!

using System;
using System.Collections.Generic;
using System.IO;

namespace file
{
    class Program
    {
        static void Main(string[] args)
        {

            var hobbies = new List<string>() { };
            Console.WriteLine("Please enter your name");
            string myName = Console.ReadLine();
            Console.WriteLine("Tell me something about you");
            string myAbout = Console.ReadLine();
            Console.WriteLine("What kind of hobbies do you have?");
            string myHobbies = Console.ReadLine();
            hobbies.Add(myHobbies);
            var query = myName + 'n' + myAbout + 'n' + myHobbies;
            File.AppendAllLines("C:test.txt", query);

        }
    }
}

回答

正如文档中File.AppendAllLines所述,方法签名是

public static void AppendAllLines (string path, 
System.Collections.Generic.IEnumerable<string> contents);

即第二个参数应该是 anIEnumerable<String>并且你正在传递query,它是 a String。您可能想要AppendAllText,它在第二个参数中接收一个字符串。


以上是C#无法将“字符串”转换为“System.Collections.Generic.IEnumerable&lt;string&gt;的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>