【问题标题】:Populate Tuple list with SQlite data Xamarin使用 SQlite 数据填充元组列表 Xamarin
【发布时间】:2017-12-15 13:03:11
【问题描述】:

我有一个主要用 C# 编写的 Xamarin 应用程序。 在 de app 中,我有一个 SQlite 数据库,其中存储了一个 Int (ID)、一个字符串和两个双精度数。

我需要元组列表中的字符串和两个双精度数。

虽然我知道如何将信息放入普通列表中,但我不知道如何将其放入元组中。

我如何填充普通列表:

protected override async void OnAppearing()
    {
        devListLoc.ItemsSource = await App.Database.GetAllLocations();
    }

我如何在没有 SQlite 的情况下填充元组:

List list = new List<Tuple<string, double, double>>
        {
            new Tuple<string, double, double>("tesst1", 57.434180, 7.236162),
            new Tuple<string, double, double>("test2", 58.435602, 8.234298),
        };

所以我想以同样的方式填充元组列表,但我不知道如何,也无法在其他地方找到答案。

干杯!

编辑: GetAllLocations 任务:

public Task<List<BarLoc>> GetAllLocations()
    {
        return database.QueryAsync<BarLoc>("SELECT * FROM [BarLoc]");
    }

【问题讨论】:

    标签: c# list sqlite xamarin.forms tuples


    【解决方案1】:
    using System.Linq;
    
    var locations = await App.Database.GetAllLocations();
    
    var tuples = (from l in locations 
                  select new Tuple<string,double,double>(l.Name, l.Lat, l.Long)).ToList(); 
    

    【讨论】:

    • 谢谢,但它得到以下错误:找不到源类型'Task>'的查询模式的实现。未找到“选择”我在问题中添加了 GetAllLocations 任务代码,因为这就是它在谈论的内容。 (我忘了添加它,哎呀)
    • 你需要等待它 - 我把它从我的原始回复中遗漏了
    猜你喜欢
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多