C# add validation on a setter method

前端 未结 5 1146
花落未央
花落未央 2020-12-03 05:58

I have a a couple of variables that i define in C# by:

public String firstName { get; set; }
public String lastName { get; set; }
public String organization          


        
5条回答
  •  执笔经年
    2020-12-03 06:40

    I wouldn't add validation in the setter at all. Rather, I would create a function called validate instead...that way all your validation code is in one spot rather scattered throughout your setters.

提交回复
热议问题