問題描述
我有一個解決方案,在通過 Visual Studio 2015 運行時構建良好,但是當我從命令行運行時遇到錯誤
I have a solution which builds fine when running through Visual Studio 2015 but when I run from the command line I run into the error
錯誤 CS1056:此行出現意外字符$"
error CS1056: Unexpected character '$' on this line
var CutOffTextFragment = deadLineTime.Deadline.Minute == 0 ? $"{deadLineTime.Deadline:htt}" : $"{deadLineTime.Deadline:h:mmtt}"
deadLineTime.Deadline 是一個 DateTime 對象,代碼將返回 XAM/PM 或 X:XXAM/PM
deadLineTime.Deadline is a DateTime object, the code will return either XAM/PM or X:XXAM/PM
我認為這是因為構建腳本沒有使用 C#6.目前此腳本無法更改為使用 c# 6
I think this is occuring becuase the build script is not using C#6. At present this script cant be changed to use c# 6
如果是這種情況,任何人都可以幫我貶低代碼以便它與 C# 5 一起使用
If this is the case, can anyone help me depreciate the code so it works with C# 5
推薦答案
$可以轉換成string.format.
$ can be converted to string.format.
var CutOffTextFragment = deadLineTime.Deadline.Minute == 0
?
string.Format("{0:htt}",deadLineTime.Deadline)
:
string.Format("{0:h:mmtt}", deadLineTime.Deadline);
這篇關于項目使用 Visual Studio 構建良好,但從命令行失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!