Adding the namespaces
Now, we will make code as follows. We'll need the LINQ and generic collections namespaces; so, enter the following under using System
near the top of the file:
using System.Linq; using System.Collections.Generic;
Creating the person and car classes
We'll make two classes. One will be a person
and the other will be a car
class. To do this, enter the following directly above the line that begins with public partial class _Default...
:
public class Person
Now, we need just a name; so, enter the following between a set of curly braces below this line:
public string Name { get; set; }
Then, we also need to make a class called Car
. So, beneath the closed curly brace underneath the preceding line, enter the following:
public class Car
Next, enter the following between a set of curly braces below this line:
public Person Owner { get; set; }
As you can see now, public Person
is being defined inside the class as a data type of a field. For example, a car has an owner.
Now, add one more data...