As already mentioned, this is bad code simply because the method is really redundant. It returns (provided that User.Username matches the parameter) the same parameter value. However, since you mentioned another reason, this is bad because it does not verify that the User is null before he tries to return the username.
Another potential problem: GetUser may throw an exception that is not handled in the method (it can actually be handled externally or internally). Just a thought ...
An improvement would be to return a User object, not a username:
public User GetUser(string username) { try { return DBLookup.GetUser(username); } catch (DBLookupException ex) { // throw exception or handle exception return null; } }
source share