Ely*_*Ely 1 c# string-formatting
我试图将a DateTime和int属性转换为foreach循环中的字符串.我需要将存储在对象属性中的信息放入变量中,然后使用该信息使用StreamWriter写入文本文件.我不太确定我做错了什么. Parse带有此错误消息的红色下划线 -
错误2'字符串'不包含'Parse'的定义
这是我的代码 -
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;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
使用DateTime和Int32类的ToString()方法获取指定类型的字符串表示形式.一些ToString()方法提供重载来定义字符串值的格式.
foreach (Appointment appointment in appointments)
{
appointStart = appointment.Start.ToString();
appointLength = appointment.Length.ToString();
appointDescription = appointment.DisplayableDescription;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59 次 |
| 最近记录: |