I have an MVC3 C#.Net web app. I have the below string array.
public static string[] HeaderNamesWbs = new[]
{
Well you can use Array.IndexOf:
int index = Array.IndexOf(HeaderNamesWbs, someValue);
Or just declare HeaderNamesWbs as an IList instead - which can still be an array if you want:
public static IList HeaderNamesWbs = new[] { ... };
Note that I'd discourage you from exposing an array as public static, even public static readonly. You should consider ReadOnlyCollection:
public static readonly ReadOnlyCollection HeaderNamesWbs =
new List { ... }.AsReadOnly();
If you ever want this for IEnumerable, you could use:
var indexOf = collection.Select((value, index) => new { value, index })
.Where(pair => pair.value == targetValue)
.Select(pair => pair.index + 1)
.FirstOrDefault() - 1;
(The +1 and -1 are so that it will return -1 for "missing" rather than 0.)