如何在xam.plugin.settings中存储整数值?

时间:2019-04-19 01:46:59

标签: c# xamarin.forms

我在我的xamarin表单项目中一直使用James的设置插件,但是我一直存储字符串值。现在,我有理由要在设置中存储整数值。有人知道我该怎么做吗?

2 个答案:

答案 0 :(得分:1)

您可以尝试这样

public class AppSettings
{        
    private static ISettings Settings => CrossSettings.Current;

    public static int Age
    {
        get => Settings.GetValueOrDefault(nameof(Age), 0);

        set => Settings.AddOrUpdateValue(nameof(Age), value);
    }
}

答案 1 :(得分:0)

公共类AppSettings {
    私人静态ISettings设置=> CrossSettings.Current;

private static string PhoneNumberKey = "PhoneNumberKey";
public static int PhoneNumber
{
    get => Settings.GetValueOrDefault(nameof(PhoneNumberKey), 0);

    set => Settings.AddOrUpdateValue(nameof(PhoneNumberKey), value);
}

}