I have a function that does a long task and I want to update a variable somewhere else occasionally with status updates. (If there is a better method for doing this, that’s fine too) I’m writing a library and this code might be called several times at once so creating another variable in the same class that stores the variable isn’t an option. Here is what my code might look like:
public static bool Count(int Progress, int CountToWhat) {
for (int i = 0; i < CountToWhat; i++) {
Progress = CountToWhat / i; // This is how I'd like to update the value, but obviously this is wrong
Console.WriteLine(i.ToString());
}
}
Change the signature to:
And when you call it, use the ref keyword before the variable that you pass in as the first argument.