
- 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 display the last three elements from a list in reverse order
To display the last three elements from a list, use the Take() method. For reversing it, use the Reverse() method.
Firstly, declare a list and add elements to it −
List<string> myList = new List<string>(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four");
Now, use the Take() method with Reverse() to display the last three elements from the list in reverse order −
myList.Reverse<string>().Take(3);
The following is the code −
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List<string> myList = new List<string>(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); // first three elements var res = myList.Reverse<string>().Take(3); // displaying last three elements foreach (string str in res) { Console.WriteLine(str); } } }
Output
Four Three Two
- Related Articles
- C program to display numbers in reverse order using single linked list
- C# Program to display a string in reverse alphabetic order
- C# Program to get the first three elements from a list
- Python program to create a Circular Linked List of n nodes and display it in reverse order
- Python program to create a doubly linked list of n nodes and display it in reverse order
- Python Program to extracts elements from a list with digits in increasing order
- How to print the elements in a reverse order from an array in C?
- Python Program to Create a Linked List & Display the Elements in the List
- Python program to print the elements of an array in reverse order
- Display a TreeSet in reverse order in Java
- Python Program to Display the Nodes of a Linked List in Reverse using Recursion
- Java Program to Get First and Last Elements from an Array List
- Python program to interchange first and last elements in a list
- Python Program to Display the Nodes of a Linked List in Reverse without using Recursion
- Sort a List in reverse order in Java

Advertisements