假设我有
public void method1(){
String s1="";
String s1=getText();
if(MyValidation.isOk(s1)){
dosomethingWith s1 here
then
method2(s1);
}
}
public void method1(String s1){
if(MyValidation.isOk(s1)){ // do we need this line of code??
//do something
}
}
对于良好的编码习惯,
如果我们已经在方法 1 中验证过数据并且方法 1 将该数据传递给方法 2,我们还需要在方法 2 中再次验证数据吗?
最佳答案
因为它是一个公共(public)方法,所以不能保证 method1(string) 永远只会从 method1() 调用,是吗?
关于c# - 对于良好的编码实践,如果我们已经在方法 1 中验证并且方法 1 将该数据传递给方法 2,我们是否仍然需要在方法 2 中再次验证数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21496151/