Ad
  • Custom User Avatar

    I arrived at a similar solution. Is it possible to pass a null string?

  • Custom User Avatar

    Hey, thanks for the feedback.

    While you are correct consider that there was no expected behaviour specified, e.g. should we return null oder string.Empty, which is the reason for me letting the method raise an exception in the case of the parameter being null.

  • Default User Avatar

    I completly agree with that comment.

    Adding a null check will solve this at the start of the function. It isn't too clear what to do for error case. I suppose returning 'null' would be ok, but throwing a new ArgumentNullException works too.

  • Custom User Avatar
    • Maskify.Maskify(""); // should return ""

    Throwing an exception is not "change all but four chars.."

    And null is not "".

    In nearly all cases where you're passing null instead of a string, it is an error. IMO, it should cause an exception, unless you have a well-defined behavior for that case, as otherwise you're allowing bugs to propagate.

    And let the caller, who I assume have accee to user interface and such, to handle possible errors caused by a null string

    Except you're making it much more difficult to handle those errors at the source.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Most of the other solutions will fail if cc == null as well...and frankly, that's the right thing to do, unless the problem specifies a behavior for that case.

  • Custom User Avatar

    I'd suggest that two test cases are added, one where the input argument (cc) is null and where the input argument (cc) is string.Empty;

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This solution will fail if the argument (cc) == null => Calling Length property will throw a "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

  • Custom User Avatar

    This solution will fail if the argument (cc) == null => Calling Length property will throw a "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

  • Custom User Avatar

    This solution will fail if the argument (cc) == null => Calling Length property will throw a "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

  • Custom User Avatar

    This solution will fail if the argument (cc) == null => Calling Length property will throw a "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

  • Custom User Avatar

    This solution will fail if the argument (cc) == null => Calling Length property will throw a "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

  • Custom User Avatar

    This solution will fail if the argument (cc) == null => Calling ToCharArray method will throw a "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

  • Loading more items...