What is the use of Peek method present in non generic stack collection class ?
Peek is same as Pop method, both will remove data from Stack in LIFO order.
Peek is used only for removing First inserted item.
Peek is used for reading Last inserted item without removing it.
Peek used for removing last inserted item .
See the sample code for better understanding .
Stack s = new Stack();
//Now count number of values present in stack , it will give you 3 as count.
//Hence peek method will not remove items but it gives Last inserted item .
int count = s.Count;
Back To Top