在C#中设置默认值

186

我尝试在C#中设置默认参数,因此,如果QueryString中没有字符串,它将使用“今天”

public int theDay
{
    get { return Convert.ToInt16(Request.QueryString["d"]); }
    set {

        if ( value <= 31 && value > 0 )
            {
                theDay = value;
            }
            else {
                theDay = DateTime.Now.Day;
            }
        }
}
Mybirthname
private int _theDay = DateTime.Now.Day;

public int TheDay
{
     get 
     {
         if(Request.QueryString["d"] != null) 
              _theDay =  Convert.ToInt16(Request.QueryString["d"]);             

         return _theDay; 
     }
     set 
     {

        if ( value <= 31 && value > 0 )
        {
            _theDay= value;
        }
        else 
        {
            _theDay= DateTime.Now.Day;
        }
    }
}

您的案子需要类似的东西。如果QueryString [“ d”]的可能值> 31或<0,则也应该进行此检查。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章