Quantcast
Viewing all articles
Browse latest Browse all 204402

Problem with using Add when trying to add a class to a list

Hi,

I've had a problem with a simple bit of code. When a button is clicked an activity should be added to a list of activities. The code is below, I don't understand why it does not add it when it is so simple, i'm probably missing something very obvious?? Thanks in advance

`namespace serialiser
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

    public void Serialiser(object sender, EventArgs args)
    {
        SelfCare selfCare = new SelfCare();

        // add activities
        var myActivity1 = new Activity()
        {
            Category = "Fitness",
            ActivityDescription = "Boxing class",
        };

        selfCare.Activities.Add(myActivity1);
    }

    public class SelfCare
    {
        public List<Activity> Activities { get; set; }

        public SelfCare()
        {
            Activities = new List<Activity>();
        }
    }

    public class Activity
    {
        public String ActivityDescription { get; set; }
        public String Category { get; set; }
    }
}

}
`


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>