我有这个代码

public static void GetOnline1()
        {
            string query = "SELECT online FROM online";
            SQLiteCommand myCommand = new SQLiteCommand(query, myConnection);
            myConnection.Open();
            SQLiteDataReader result = myCommand.ExecuteReader();
            if (result.HasRows)
            {
                while (result.Read())
                {
                    Console.WriteLine(result["online"]);
                    //result["online"] to string array?
                }
            }
            myConnection.Close();


我如何将result [“ online”]转换为字符串数组?

最佳答案

将结果放在List<string>中:

var onlineList = new List<string>();
if (result.HasRows)
{
    while (result.Read())
    {
        Console.WriteLine(result["online"]);
        onlineList.Add(result["online"].ToString());
    }
}


如果需要将其作为数组,则可以使用以下命令:onlineList.ToArray()

关于c# - 将SQLite选择查询转换为字符串数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57605340/

10-12 03:00