0

I've been trying to understand passing by reference and passing by value and trying to understand it lead me to trying to understand reference data types. In all the explanations I've seen online they define a reference data type to be referencing data as opposed to containing data, and i'm wandering what is the difference?

What i think so far is that the variable doesn't contain data itself but it is referencing a method, but i don't feel like that is a satisfactory understanding. Hopefully someone could clear this up for me.

user8077453
  • 15
  • 1
  • 3
  • 4
    http://jonskeet.uk/csharp/references.html (this should have been covered in the book/tutorial you're using to learn C#) – Cody Gray - on strike May 28 '17 at 12:32
  • 1
    These topics are very broad but it seems to me that you're confused. Please note that "reference types" vs. "value types" are orthogonal topics compared to "passing by reference" vs. "passing by value". You can pass a reference by value and you can pass a value type by reference. Can you please focus on one question at a time? – Lasse V. Karlsen May 28 '17 at 12:36
  • See also: http://jonskeet.uk/csharp/parameters.html – Jon Skeet May 28 '17 at 12:45
  • Reference types are a reference an object that contains the data - it's not opposed to. – Enigmativity May 28 '17 at 12:45
  • Aha, i think i understand now. Jon Skeet's analogy was really good thank you i appreciate it. – user8077453 May 28 '17 at 22:20

1 Answers1

0

When you pass the reference of an variable, you are actually sending the memory address of that variable, whoever getting the address will be able to change your variable's value. but if you are passing by value, you are sending a copy of your variable, so even if the receiver changes the value of that variable, you will still get the original value of your variable.

Badhon Jain
  • 938
  • 6
  • 20
  • 38