Class ListExtensions
Provides extension methods for System.Collections.Generic.List%601
collections.
Namespace: Workspace.XBR.Xperiflow.Utilities.Extensions
Assembly: Xperiflow.dll
public static class ListExtensions
Examples
Using the Pop extension method:
var numbers = new List { 1, 2, 3, 4, 5 };
// Pop the last element (returns 5)
int lastNumber = numbers.Pop();
Console.WriteLine($"Popped: {lastNumber}"); // Outputs: Popped: 5
// List now contains: { 1, 2, 3, 4 }
Console.WriteLine($"Remaining count: {numbers.Count}"); // Outputs: Remaining count: 4
Remarks
This static class extends the functionality of System.Collections.Generic.List%601
with additional
utility methods that are commonly needed in collection operations. The methods
provide stack-like operations and other convenient list manipulations.
Key Features:
-
Stack OperationsStack-like operations for lists (Pop functionality)
-
Type SafetyGeneric methods that work with any list type
-
Error HandlingProper exception handling for edge cases
Usage Guidelines:
These extension methods are designed to be used directly on List instances. They provide convenient shortcuts for common operations while maintaining type safety and proper error handling.
Methods
Pop<T>(List<T>)
Removes and returns the last element from the list, similar to a stack pop operation.
public static T Pop<T>(this List<T> list)
Remarks
This method provides stack-like functionality for lists by removing and returning the last element. The list is modified in-place, and the returned element is no longer part of the list.
Behavior:
- Removes the element at the last index (Count - 1)
- Returns the removed element
- Reduces the list count by 1
- Does not modify the list if an exception occurs
Returns
<T>
The last element that was removed from the list
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<{T}> | list | The list to pop from |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list |
Exceptions
System.ArgumentNullException
Thrown when list is null
System.InvalidOperationException
Thrown when the list is empty
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object,System.Object)
System.Object.GetHashCode
System.Object.GetType
System.Object.MemberwiseClone
System.Object.ReferenceEquals(System.Object,System.Object)
System.Object.ToString