Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Example {
- public static void Main() {
- int variable = 0;
- bool success = SomeProcedureWithRef(ref variable);
- // At this point success == true, variable == 10
- // This declaration is ok because after the call outVariable must have been set
- int outVariable;
- bool success = SomeProcedureWithOut(out outVariable);
- // At this point success == false, variable == 20
- }
- public static bool SomeProcedureWithRef(ref int value) {
- value = 10; // This is optional (but often helpful)
- return true;
- }
- public static bool SomeProcedureWithOut(out int value) {
- value = 20; // Compile time error if not setting value
- return false;
- }
- }
Add Comment
Please, Sign In to add comment