C# Stack Contains

Description

Stack Contains determines whether an element is in the Stack.

Syntax

Stack.Contains has the following syntax.


public bool Contains(
  T item
)

Parameters

Stack.Contains has the following parameters.

  • item - The object to locate in the Stack . The value can be null for reference types.

Returns

Stack.Contains method returns true if item is found in the Stack; otherwise, false.

Example


using System;/*  w  ww  .j  a va  2s  .  com*/
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>();
        numbers.Push("one");
        numbers.Push("two");
        numbers.Push("three");
        numbers.Push("four");
        numbers.Push("five");

        Console.WriteLine(numbers.Contains("four"));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack