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.
But my question is, which data types are reference types by default?
Anything that is defined as a class is a reference type, as well as a variable referencing an interface or delegate, or a variable declared dynamic. See Reference Types for details. You can change members of a class within a method without passing by ref or out. 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 via out or ref.
If it's a struct, it will be a value type.
A better question is what types are not reference types.
MSDN documentation
Structs fall into these categories:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With