This is my code in ASP.Net C#
ArrayList myArrayList = new ArrayList();
myArrayList.Add("Apple");
myArrayList.Add("Banana");
if (myArrayList.Contains("apple")) // This returns false because Contains doesn't support a case-sensitive search
statusLabel.Text = "ArrayList contains apple";
I get false , Since Apple not equals apple. I have even tried like
myArrayList.Contains("apple", StringComparer.OrdinalIgnoreCase)
But intellisense shows error. Is this really possible on ArrayList ?apple
If you are using .NET 1.1 because Generics aren’t available, you could do something like this:
Otherwise, using
List<string>instead of ArrayList, thenmyArrayList.Contains("apple", StringComparer.OrdinalIgnoreCase)will work.If you have .NET 2 + Generics available to you; then there really is no good reason to be using the
ArrayListanymore.