C#获取编译时间作为版本

参考:C#获取程序集的版本号和最后编译时间

获取编译时间代码为:

        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;

        }
    }

最终运行效果为:

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值