首页 > 解决方案 > 我不明白代码的 Try Catch Exception 部分

问题描述

在一个项目中,我发现了这部分代码:

public String EndDateText
    {
        get
        {
            try
            {
                if (_endDate != null)
                    return _endDate.Value.ToString("o");
                else
                    return "";
            }
            catch (Exception)
            {
                _endDate = new DateTimeOffset();
                throw;
            }
        }
        set
        {
            if (value != null)
                _endDate = DateTimeOffset.Parse(value);
        }
    }

我不明白这行_endDate = new DateTimeOffset(); 在捕获部分。

为什么要创建 _endDate 的新实例?

感谢您的帮助。

标签: c#

解决方案


推荐阅读