Link to home
Start Free TrialLog in
Avatar of Stacie
StacieFlag for United States of America

asked on

simple class explanation

I was wondering what the public Patien( Visist = New List<Visit>) in this code mean.  Is it a method that refer to a new class List?

Class Patient {
 public Patient() {
            Visits = new List<Visits>();
        }

        public int ID { get; set; }
        public string Name { get; set; }
        public DateTime BirthDate { get; set; }
        public AnimalType AnimalType { get; set; }
        public DateTime FirstVisit { get; set; }


}
Class Visist{
 Public int Id {get; set;}
 Public int PatientId { get; set;}

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And this will give you a better idea of what is happening:
using System;
using System.Collections.Generic;

namespace EE_Q28647864
{
	class Program
	{
		static readonly Basket PicnicBasket = new Basket();

		static void Main(string[] args)
		{
			Console.WriteLine("Adding an orange to the Fruit list in the PicnicBasket");
			PicnicBasket.Fruit.Add(new Fruit() { Name = "Orange", HasSeeds = true });
			Console.WriteLine("Adding a peanut butter sandwich to the Sandwich list in the PicnicBasket");
			PicnicBasket.Sandwiches.Add(new Sandwich() { Name = "Peanut Butter", HasCheese = false });
			Console.WriteLine("Adding grapes to the Fruit list in the PicnicBasket");
			PicnicBasket.Fruit.Add(new Fruit() { Name = "Grapes", HasSeeds = false });
			Console.WriteLine("Adding a ham sandwich to the Sandwich list in the PicnicBasket");
			PicnicBasket.Sandwiches.Add(new Sandwich() { Name = "Ham", HasCheese = true });

			Console.WriteLine("Here are the fruit");
			foreach (var item in PicnicBasket.Fruit)
				Console.WriteLine(item);

			Console.WriteLine();

			Console.WriteLine("Here are the sandwiches");
			foreach (var item in PicnicBasket.Sandwiches)
				Console.WriteLine(item);

			Console.ReadLine();
		}
	}

	class Basket
	{
		private List<Fruit> fFruit;
		private List<Sandwich> fSandwiches;

		public List<Fruit> Fruit
		{
			get 
			{
				if (fFruit == null)
				{
					Console.WriteLine("Fruit list is not initialized.  Initializing a new list.");
					fFruit = new List<Fruit>();
				}

				return fFruit; 
			}
			set
			{
				if (!value.Equals(fFruit))
					fFruit = value;
			}
		}

		public List<Sandwich> Sandwiches
		{
			get
			{
				if (fSandwiches == null)
				{
					Console.WriteLine("Sandwich list is not initialized.  Initializing a new list.");
					fSandwiches = new List<Sandwich>();
				}

				return fSandwiches;
			}
			set
			{
				if (!value.Equals(fSandwiches))
					fSandwiches = value;
			}
		}
	}

	class Fruit
	{
		public string Name { get; set; }
		public bool HasSeeds { get; set; }
		public override string ToString()
		{
			return string.Format("{0} {1}", Name, HasSeeds ? "has seeds." : "does not have seeds.");
		}
	}

	class Sandwich
	{
		public string Name { get; set; }
		public bool HasCheese { get; set; }
		public override string ToString()
		{
			return string.Format("{0} {1}", Name, HasCheese ? "has cheese." : "does not have cheese.");
		}
	}
}

Open in new window

Now produces the following output -User generated image-saige-
@it_saige

but unlike arrays, Lists are a type-safe object
Arrays are type safe as well--provided you don't create an array of objects. Are you sure you weren't referring to ArrayList?