I am trying to convert a DateTime
and an int
property into a string in a foreach loop. I need to put the information that is stored in the objects properties into the variables and then use that info to write to a text file using StreamWriter. I'm not quite sure what I am doing wrong. Parse
is red underlined with this error message -
Error 2 'string' does not contain a definition for 'Parse'
Here is my code -
public bool Save()
{
string appointStart;
string appointLength;
string appointDescription;
foreach (Appointment appointment in appointments)
{
appointStart = string.Parse(appointment.Start);
appointLength = string.Parse(appointment.Length);
appointDescription = appointment.DisplayableDescription;
}
return true;
}
Thank you
Use the ToString() methods of DateTime and Int32 class to get a string representation of the specified types. Some ToString() methods provide overloads to define the formatting of the string value.