I have not much worked around with value type pass by refrence, but long back i had passed a struct by ref, today I hit upon a function in .net framework "CheckReaderCount" which takes 2 int by "ref" i was wondering what it exactly would be requirement to do so???? would it be changing value of int parameter inside the function in that why not Integer object is taken as parameter???? Just trying to understand ref use in this case.
Asked
Active
Viewed 59 times
1 Answers
1
Simply - it is reading and changing the value of both parameters; whileIterations
is incremented and compared in a bitwise test, and readerCount
is compared to a particular property value (equality being an error condition), and (assuming it didn't error), assigned that property value.
The only non-ref
way to read and change two values (assuming we don't hoist them onto a separate object as fields) would be to pass them both in as parameters and return some kind of tuple that the caller then decomposes to update the local variables (etc). A simple ref
/ref
is simpler.

Marc Gravell
- 1,026,079
- 266
- 2,566
- 2,900
-
got the idea. As function needs to multiple (2 int) value to calle going this way makes sense. – Pritesh Apr 23 '12 at 07:36