Last active
February 11, 2020 22:47
-
-
Save evanricard/fd7319ba64cf7701b75c04b23545e4ee to your computer and use it in GitHub Desktop.
ref
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
static void Main() | |
{ | |
var store = new NumberStore(); | |
WriteLine($"Исходная последовательность: {store.ToString()}"); | |
ref var value = ref store.FindNumber(16); | |
value *= 2; | |
WriteLine($"Новая последовательность: {store.ToString()}"); | |
//: 1 3 7 15 31 63 127 255 511 1023 | |
//: 1 3 7 15 62 63 127 255 511 1023 | |
} | |
class NumberStore | |
{ | |
int[] numbers = { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023 }; | |
public ref int FindNumber(int target) | |
{ | |
ref int returnVal = ref numbers[0]; | |
var ctr = numbers.Length - 1; | |
while ((ctr > 0) && numbers[ctr] >= target) | |
{ | |
returnVal = ref numbers[ctr]; | |
ctr--; | |
} | |
return ref returnVal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment