Created
August 31, 2010 09:56
-
-
Save anelson/558817 to your computer and use it in GitHub Desktop.
Using return values, ref, and out parameters, Kyiv 2010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When a method outputs two or more values, use output parameters and return void | |
public void GetUserInfo(out string userName, out string password) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When a method takes an argument for input, also changes the argument for output, use a ref parameter | |
// | |
// That said, a method that changes its input arguments like this is a very bad idea, so don't do it! | |
public void DontDoThis(ref User user) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A return value is useful when a method outputs a single value | |
public User CreateUserObject(string userName, string password) { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment