L
L
ldmitriy2020-06-04 17:23:16
C++ / C#
ldmitriy, 2020-06-04 17:23:16

How are the records for creating a class object different?

class A
    {
        public int X { get; set; }
        public int Y { get; set; }

        public A(int x, int y)
        {
            X = x;
            Y = y;
        }

        public void test() { }
    }


A a1 = new A(1, 2); //such record
A a2=null; // from such
a2.X = 1;
a2.Y = 2;
a2 test();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-06-04
@ldmitriy

A a2- this is nothing, you just described the signature of the variable, consider just a violin case. Until you have created an object (violin) via new, which you put in the case, you cannot do anything with the case. You can't play the violin a2.X = 1;if you don't have one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question