
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
LinkedList Contains Method in C#
Here is our LinkedList.
int [] num = {1, 3, 7, 15}; LinkedList<int> list = new LinkedList<int>(num);
To check whether the list contains an element or not, use the Contains() method. The following example checks for node 3 in the list.
list.Contains(3)
Above, returns True since the element is found as shown below −
Example
using System; using System.Collections.Generic; class Demo { static void Main() { int [] num = {1, 3, 7, 15}; LinkedList<int> list = new LinkedList<int>(num); foreach (var n in list) { Console.WriteLine(n); } // adding a node at the end var newNode = list.AddLast(20); // adding a new node after the node added above list.AddAfter(newNode, 30); Console.WriteLine("LinkedList after adding new nodes..."); foreach (var n in list) { Console.WriteLine(n); } Console.WriteLine("Is number 3 (node) in the list?: "+list.Contains(3)); } }
Output
1 3 7 15 LinkedList after adding new nodes... 1 3 7 15 20 30 Is number 3 (node) in the list?: True
- Related Articles
- LinkedList AddFirst method in C#
- LinkedList AddAfter method in C#
- LinkedList Remove method in C#
- LinkedList RemoveFirst() Method in C#
- LinkedList RemoveLast() Method in C#
- LinkedList Clear() Method in C#
- LinkedList AddLast method in C#
- LinkedList AddBefore method in C#
- C# Linq Contains Method
- LinkedList in C#
- ArrayBlockingQueue contains() method in Java
- Removing all nodes from LinkedList in C#
- Singly LinkedList Traversal using C#
- HTML DOM contains() Method
- Copy the entire LinkedList to Array in C#

Advertisements