A
A
Alexander Vladimirov2020-12-15 04:14:59
C++ / C#
Alexander Vladimirov, 2020-12-15 04:14:59

It is not possible to display the property of the class obtained from the list. How can I do it?

There is a class, I am adding objects of this class to an ArrayList. Then I need to get this object back, let's say by index, and display the class property. It doesn't work for me, it gives an error object does not contain a Name definition, here is part of the code

var NewPasp = new Pasport();
 NewPasp.Addd(Nomer, Seria, Family, Name, SecondName);
                pasports.Add(NewPasp);

            var GetPasp = pasports[0];
            Console.WriteLine(GetPasp.Name);// нужно вывести свойство Name объекта из листа pasports

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-12-15
@zolotoy1008

Because, by index, you get an object, not an object of its type
1. We cast the type 2. We use a collection generic, for example List, instead of ArrayList var GetPasp = (Passport)pasports[0];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question