0

I just stumpled upon the "in" modifier in C#. I know and used ref/out before, but when would you use "in"?

When would you actually pass as reference parameter but not want to change the content? Couldn't you just pass it regularly? If I am the writer of the method I could just not use in, couldn't I?

Thypari
  • 801
  • 1
  • 6
  • 22
  • `in` its something like `const` in C++. This guarantees that value will not be changed. – Kevin Kouketsu Nov 29 '18 at 16:51
  • Mostly it is used in the foreach loop. I guess you could need it in a similar case, where you want to make sure you don't change the object you are looping over, or comparing to, possibly ending up in an exception or an infinite loop. – Roland Deschain Nov 29 '18 at 16:55

0 Answers0