
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find First Node in LinkedList Containing Specified Value in C#
To find the first node in LinkedList containing the specified value, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<string> list = new LinkedList<string>(); list.AddLast("John"); list.AddLast("Tim"); list.AddLast("Kevin"); list.AddLast("Jacob"); list.AddLast("Emma"); list.AddLast("Ryan"); list.AddLast("Brad"); list.AddLast("Carl"); Console.WriteLine("LinkedList elements..."); foreach(string str in list){ Console.WriteLine(str); } LinkedListNode<string> val = list.Find("Jacob"); Console.WriteLine("Specified value = "+val.Value); } }
Output
This will produce the following output −
LinkedList elements... John Tim Kevin Jacob Emma Ryan Brad Carl Specified value = Jacob
Example
Let us now see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<int> list = new LinkedList<int>(); list.AddLast(100); list.AddLast(200); list.AddLast(300); list.AddLast(400); list.AddLast(500); Console.WriteLine("LinkedList elements..."); foreach(int i in list){ Console.WriteLine(i); } LinkedListNode<int> val = list.Find(300); Console.WriteLine("Specified value = "+val.Value); } }
Output
This will produce the following output −
LinkedList elements... 100 200 300 400 500 Specified value = 300
Advertisements