So while I was testing a method I made with a DataRow parameter, I sent in an argument and modified it inside the method. After that, my original DataRow changed to whatever it ended up being after the method. I realized this was because DataRow is a “reference type”, which is new to me.
I now know that I can use “ref” or “out” before other data types when using methods so that the same effect as the DataRow example would happen. But my question is, which data types are reference types by default? I don’t want to be caught off guard when I pass another kind of data type into a method and having the original value change.
Anything that is defined as a
classis a reference type, as well as a variable referencing aninterfaceor delegate, or a variable declareddynamic. See Reference Types for details. You can change members of a class within a method without passing byreforout. That being said, you can’t change the reference itself – so the variable will always point to the same instance after a method call as before the method call unless you pass it viaoutorref.If it’s a
struct, it will be a value type.