K
K
Ksenia2019-02-23 19:42:40
C++ / C#
Ksenia, 2019-02-23 19:42:40

Copying an object or passing a reference to it?

Something I can't figure out. Here is an example:

using System;

class MyClass {

   static void Main() {
      object o = null;
      object p = null;
      object q = new Object();

      Console.WriteLine(Object.ReferenceEquals(o, p));
      // Вот здесь происходит копирование ссылки или же объекта?
      p = q;
      // Что сравнивает между собой ReferenceEquals, ссылки или объекты? Как сравнивает?
      Console.WriteLine(Object.ReferenceEquals(p, q));
      Console.WriteLine(Object.ReferenceEquals(o, p));
   }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VoidVolker, 2019-02-23
@VoidVolker

Read the IEquatable interface manual: https://docs.microsoft.com/en-us/dotnet/api/system...
This interface implements comparison methods of a certain class. In addition, the class can also implement comparison support for operators (equal, not equal, greater than / less than, etc.).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question