C# Programming - Collection Classes - Discussion

Discussion :: Collection Classes - General Questions (Q.No.6)


Which of the following statements are correct about the C#.NET code snippet given below?

Stack st = new Stack();

[A]. Dissimilar elements like "hello", 8.2, 5 cannot be stored in the same Stack collection.
[B]. Boolean values can never be stored in Stack collection.
[C]. In the fourth call to Push(), we should write "b" in place of 'b'.
[D]. To store dissimilar elements in a Stack collection, a method PushAnyType() should be used in place of Push().
[E]. This is a perfectly workable code.

Answer: Option E


No answer description available for this question.

Syed said: (Mar 2, 2013)  
Since Push method take parameter as object. Hence any data type can be stored in the Stack object.

Farhat said: (Apr 20, 2014)  
At the very first line we can't declare stack like that we have to define the generic type of stack here.

Sridhar said: (Jul 4, 2018)  
Only value data type can stored stack. Then how option E is right?

Sangeetha.T said: (Mar 1, 2019)  
Implement collection namespace. So you can see a stack option. In which it accepts all data type because it requires only an object not a specific datatype.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.