-
Notifications
You must be signed in to change notification settings - Fork 0
ArrayList Extensions
Andrzej Kebab edited this page Jan 21, 2024
·
1 revision
Checks if the ArrayList is null or empty.
using UtilityLibrary.Core;
using System;
using System.Collections;
ArrayList list1 = new ArrayList();
ArrayList list2 = null;
bool isNullOrEmpty1 = list1.IsNullOrEmpty();
bool isNullOrEmpty2 = list2.IsNullOrEmpty();
// Result: isNullOrEmpty1 = true, isNullOrEmpty2 = trueChecks if the ArrayList is empty, throwing an exception if it is null.
using UtilityLibrary.Core;
using System;
using System.Collections;
ArrayList list = new ArrayList();
bool isEmpty = list.IsEmpty();
// Result: isEmpty = trueRetrieves the first element of the ArrayList.
using UtilityLibrary.Core;
using System;
using System.Collections;
ArrayList list = new ArrayList { 1, 2, 3, 4, 5 };
object firstElement = list.First();
// Result: firstElement = 1Retrieves the first element of the ArrayList and casts it to the specified type.
using UtilityLibrary.Core;
using System;
using System.Collections;
ArrayList list = new ArrayList { 1, 2, 3, 4, 5 };
int firstElement = list.First<int>();
// Result: firstElement = 1Retrieves the last element of the ArrayList.
using UtilityLibrary.Core;
using System;
using System.Collections;
ArrayList list = new ArrayList { 1, 2, 3, 4, 5 };
object lastElement = list.Last();
// Result: lastElement = 5Retrieves the last element of the ArrayList and casts it to the specified type.
using UtilityLibrary.Core;
using System;
using System.Collections;
ArrayList list = new ArrayList { 1, 2, 3, 4, 5 };
int lastElement = list.Last<int>();
// Result: lastElement = 5