
- 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
C# Program to check whether a node is a LinkedList or not
Use the Contains() method to check whether a node is a LinkedList or not.
Here is our LinkedList.
string [] students = {"Beth","Jennifer","Amy","Vera"}; LinkedList<string> list = new LinkedList<string>(students);
Now, to check whether the node “Amy” is in the list or not, we will use the Contains() method as shown below −
list.Contains("Amy")
The method will return a Boolean value i.e. True in this case.
Let us see the complete code.
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Beth","Jennifer","Amy","Vera"}; LinkedList<string> list = new LinkedList<string>(students); foreach (var stu in list) { Console.WriteLine(stu); } // adding a node at the end var newNode = list.AddLast("Emma"); // adding a new node after the node added above list.AddAfter(newNode, "Matt"); Console.WriteLine("LinkedList after adding new nodes..."); foreach (var stu in list) { Console.WriteLine(stu); } Console.WriteLine("Is Student Amy (node) in the list?: "+list.Contains("Amy")); Console.WriteLine("Is Student Anne (node) in the list?: "+list.Contains("Anne")); } }
Output
Beth Jennifer Amy Vera LinkedList after adding new nodes... Beth Jennifer Amy Vera Emma Matt Is Student Amy (node) in the list?: True Is Student Anne (node) in the list?: False
- Related Articles
- Check whether a node is a root node or not in JTree
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C# program to check whether a list is empty or not
- Python program to check whether a list is empty or not?
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Character is Alphabet or Not
- Java Program to Check Whether a Number is Prime or Not
- Haskell Program to check whether a variable is defined or not
- C++ Program to Check Whether a Character is Alphabet or Not
- Swift Program to Check whether a number is a Perfect Cube or not
- Java program to check whether a given string is Heterogram or not
- C# program to check whether a given string is Heterogram or not
- Python program to check whether a given string is Heterogram or not
- C++ Program to Check Whether a Graph is Strongly Connected or Not

Advertisements