如果沒有傳入有效數據的參數,這對我來說中止對象實例化的最佳方式是什麼?構造函數和拋出異常
protected Command(string commandKey)
{
if(commandKey == null) throw new ArgumentNullException("commandKey", "Command Key cannot be null as it is required internally by Command");
if(commandKey == "") throw new ArgumentException("Command Key cannot be an empty string");
CommandKey = commandKey;
}
感謝您對IsNullOrEmpty方法的提示! – Chris