Hi,
I have a straight forward string array, why would IndexOf be unavailable? I'm targeting .Net 3.5
Thanks
Hi,
I have a straight forward string array, why would IndexOf be unavailable? I'm targeting .Net 3.5
Thanks
Are you talking about the Array.IndexOf method:
var array = new[] { "a", "b", "c" };
Console.WriteLine(Array.IndexOf(array, "b"));
Probably because you are assuming it is an instance method instead of a static method:
using System;
class Program {
static void Main(string[] args) {
string[] arr = new string[] { "hello", "world" };
int index = Array.IndexOf(arr, "world");
// Not:
//int index = arr.IndexOf("world");
System.Diagnostics.Debug.Assert(index == 1);
}
}
Consider List<string>
instead of an array, List<>.IndexOf() is an instance method.