简体   繁体   中英

Xamarin Forms Update value in App.xaml.cs

I have a problem. I want to set and get a variable in my App.xaml.cs, so I use this code:

static User user { get; set; }

public static User User
{
    get
    {
        if(user == null)
        {
            user = new User();
        }
        return user;
    }
    set
    {
        User = value;
    }
}

And inside a page I call this line:

App.User = response.user;

But after that line is fired, the app doesn't hit the next line and after a few seconds the app crashes. What am I doing wrong?

this causes an infinite loop

set
{
    User = value;
}

you should be doing

set
{
    user = 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