简体   繁体   中英

How can I store integer values in xam.plugin.settings?

I have always used the settings plugin by James in my xamarin forms projects but I have always stored string values. Now I have a reason to want to store integer values in settings. Does anyone know how I can do this?

You can try like this

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);
    }
}

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

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

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM