The Favoritecolor property must have both get and set accessor. Like this:
System.Drawing.KnownColor Favoritecolor
{
get;
set;
}
, - :
class Program
{
static void Main(string[] args)
{
Contact contact = new Contact();
Console.WriteLine("Please enter the person name:");
contact.Name = Console.ReadLine();
Console.WriteLine("Please enter the person e-mail address:");
contact.Email = Console.ReadLine();
while (contact.Favoritecolor == 0)
{
Console.WriteLine("Please enter the person favorite color:");
string tempColor = Console.ReadLine();
try
{
contact.Favoritecolor = (System.Drawing.KnownColor)(Enum.Parse(typeof(System.Drawing.KnownColor), tempColor, true));
}
catch
{
Console.WriteLine("The color \"" + tempColor + "\" was not recognized. The known colors are: ");
foreach (System.Drawing.KnownColor color in Enum.GetValues(typeof(KnownColor)))
{
Console.WriteLine(color);
}
}
}
}
class Contact
{
public string Name { get; set; }
public string Email { get; set; }
public System.Drawing.KnownColor Favoritecolor
{
get;
set;
}
}
}
, System.Drawing.KnownColor . , .