Access properties or attributes of an object of a class created on the fly

0

Suppose I have this code;

            new List<Int32>().Add(Int32.Parse(Console.ReadLine()));

Could I have access in any way to the number I entered in the list? Not having an object as such, I do not know if something like that would be possible ...

Thanks

    
asked by Edulon 24.02.2018 в 12:24
source

1 answer

1

The Add in that case returns a void, not a list. What could be done is the following for this specific case, to access everything without variables.

new List<Int32>() { Int32.Parse(Console.ReadLine()) }[0]

The complete example would be and this and it works OK

If you want to use it later you have to store it in a variable and then access it.

Greetings and I hope it serves you.

    
answered by 24.02.2018 / 16:27
source