C# 如何显示Apr';11带有DateTime.ToString

C# 如何显示Apr';11带有DateTime.ToString,c#,.net,C#,.net,好的,我已经用DateTime-ToString方法尝试了各种方法以2011年4月的格式呈现日期。文档中说,“是为字符串文本保留的,所以我想显示一个撇号,我会使用”——但是,不行。以下是我迄今为止所尝试的: taskdata.Month.Start.ToString("MMM 'yy") A first chance exception of type 'System.FormatException' occurred in mscorlib.dll taskdata.Month.Start.T

好的,我已经用
DateTime-ToString
方法尝试了各种方法以2011年4月的格式呈现日期。文档中说,
是为字符串文本保留的,所以我想显示一个撇号,我会使用
——但是,不行。以下是我迄今为止所尝试的:

taskdata.Month.Start.ToString("MMM 'yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
taskdata.Month.Start.ToString("MMM ''yy")
"Apr 09"
taskdata.Month.Start.ToString("MMM '''yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
taskdata.Month.Start.ToString("MMM ''''yy")
"Apr 09"
taskdata.Month.Start.ToString("MMM \'yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
taskdata.Month.Start.ToString("MMM '\''yy")
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
说真的,秘密是什么?我拒绝连接

你需要逃逸(实际上是双重逃逸):


为我工作

我拒绝连接!为什么不呢?为什么要把时间浪费在你可以自己实现和完成的事情上呢?你曾经继承过代码,然后说“呃,为什么他们那样做而不是简单的方式,显然那个人不会编码。”是的,我不想在将来成为“那个人”。@EdS。写一个更好的代码。学习新事物。实现一个挑战(嗯,通过问别人,失败:)。嘿,我最终会明白的。。奥蒂尔:我同意。我没有意识到这只是一个简单的字符转义问题,读得太快。请注意,如果使用逐字字符串文字,则不需要双重转义:
@“MMM\yy”
new DateTime(2011, 10, 1).ToString("MMM \\'yy")
String.Format(@"{0:MMM  \'yy}", DateTime.Now)