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

yguyon28Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
A List, is a generic collection type that lives in the System.Collections.Generic namespace.  Lists are very similar to arrays but unlike arrays, Lists are a type-safe object.  In your List, you are guaranteed to have only visit objects.  Like any other type, a List needs to be initialized in order for you to use it.  Since a List is a reference type, you use the new keyword in order to initialize it.  Consider the following example:
using System;
using System.Collections.Generic;

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

		static void Main(string[] args)
		{
			PicnicBasket.Fruit.Add(new Fruit() { Name = "Orange", HasSeeds = true });
			PicnicBasket.Sandwiches.Add(new Sandwich() { Name = "Peanut Butter", HasCheese = false });
			PicnicBasket.Fruit.Add(new Fruit() { Name = "Grapes", HasSeeds = false });
			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)
					fFruit = new List<Fruit>();

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

		public List<Sandwich> Sandwiches
		{
			get
			{
				if (fSandwiches == null)
					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

Which produces the following output -Capture.JPG-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it_saigeDeveloperCommented:
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 -Capture.JPG-saige-
0
käµfm³d 👽Commented:
@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?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.