-3

if it is an Object, return an address to the referenced return object? If literal, return a copied value to the return object?

Example:

public class serv{

Object add;
int literal;

public Object AddVal{
 get{return add}; set{add = value};
}

public int Literal{
 get{return literal}; set{literal = value};
}

}

Here if i retrieve item from "AddVal" would it be the reference address that is returned? If I retrieve item from Literal, wold it be copy of literal that is returned?

Thanks for your time.

JC Guy
  • 1
  • Possible duplicate of [Reference type vs value type](http://stackoverflow.com/questions/24089591/reference-type-vs-value-type) – Craig W. Oct 28 '16 at 22:44
  • `return` returns copy of value. Note, that for reference types, **value** is not object itself, but reference to object or `null` reference. – user4003407 Oct 28 '16 at 22:46
  • 1
    What do you need to know for? Just wondering because the c# return from many points of view `var thing = serv.AddVal` just assigns the return value of the getter to thing. In essence the fact it is in a return statement doesn't make it get treated any differently than anywhere else a reference/value is used. So I am left wondering why you are particularly interested in return statements in the hope that we might better address your question. – Chris Oct 28 '16 at 22:47
  • Actually, you guys answered my question. Thanks. – JC Guy Oct 28 '16 at 23:02

1 Answers1

0

If you're asking what I think you're asking then yes.

public static void Main()
{
    var i1 = 1;
    var i2 = i1;

    var o1 = new Object();
    var o2 = o1;

    Console.WriteLine(Object.ReferenceEquals(i1, i2));
    Console.WriteLine(Object.ReferenceEquals(o1, o2));
}

Demo here.

BanksySan
  • 27,362
  • 33
  • 117
  • 216
  • 1
    Perhaps you should be more explicit about what you think they are asking in case it isn't what you think they are asking? Saying yes to an unwritten (and by your own admission uncertain) question isn't that helpful... – Chris Oct 28 '16 at 22:48
  • 1
    If you write `Object.ReferenceEquals(i1, i1)`, then you also get `false`. – user4003407 Oct 28 '16 at 22:53