获取编译时间代码为:
string GetCompileVersion()
{
string OriginVersion = "" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location);
int MsgCnt = 0;
string year = "";
string month = "";
string data = "";
for (int i=0; i<OriginVersion.Length && MsgCnt<3; i++)
{
char ch = OriginVersion[i];
if (ch >= '0' && ch <= '9')
{
switch (MsgCnt)
{
case 0: year += ch; break;
case 1: month += ch; break;
case 2: data += ch; break;
}
}
else
{
MsgCnt++;
}
}
while (year.Length < 4) year = "0" + year;
while (month.Length < 2) month = "0" + month;
while (data.Length < 2) data = "0" + data;
return year + month + data;
}
加入到代码中则为:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string CurrLittleVersion = "." + GetCompileVersion();
this.Title += CurrLittleVersion;
}
}
最终运行效果为: