What exception to throw from a property setter?

后端 未结 7 2105
醉话见心
醉话见心 2020-12-08 02:24

I have a string property that has a maximum length requirement because the data is linked to a database. What exception should I throw if the caller tries to set a string ex

7条回答
  •  一生所求
    2020-12-08 03:02

    public IPAddress Address
    {
        get
        {
            return address;
        }
        set
        {
            if(value == null)
            {
                throw new ArgumentNullException("value");
            }
            address = value;
        }
    }
    

    via MSDN

提交回复
热议问题