如何获取变量的名称?

时间:2017-04-26 22:21:54

标签: c# android xamarin

我想使用sqlite数据库返回一些值,代码如下:

    public Dictionary<string, string> GetRegistry()
    {
        var table = this.connection.Table<Registry>();
        Dictionary<string, string> RegistryItems = new Dictionary<string, string>();

        foreach (var item in table)
        {

        }
    }

鉴于var item代表一个sql表项,所以说item.Age将是一个年龄,依此类推。我希望能够返回一个字典,我可以这样做:

Dictionary registry = this.GetRegistry();
int myAge = registry["Age"];

我应该在foreach条款中做些什么来实现这一目标? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

鉴于该表意味着sql表,您可以执行以下操作:

public Dictionary<string, string> GetRegistry()
        {


            var table = this.connection.Table<Registry>();
            Dictionary<string, string> RegistryItems = new Dictionary<string, string>();

            var ages = table.Select(X => x.Name == "Age").ToList();

        }