I have to write an address book program in C# 2008. It is supposed to ask the user for the person’s Name, Email, and Favorite Color (only by the colors in the enumeration). Then it is supposed to save the contacts for future reference.
This is the code the produces an error.:
class Contact
{
string Name; //This string represents the person's Name.
string Email; //This string represents the person's Email.
System.Drawing.KnownColor Favoritecolor
{
get;
}
static void Request()
// This function requests the user to type in information about the person.
{
Console.WriteLine("Please enter the person's name, e-mail, and favorite color");
Console.Write; string Name; string Email; ;
Console.ReadLine();
}
}
The error is:
'Lab02.Program.Contact.Favoritecolor': property or indexer must have at least one accessor
Right now you have a get on the FavoriteColor property, but no where is it ever set, so it can never return an actual value.
If you want to implement an auto property, you need to add a set. Otherwise create a backing field and return that.