I have an MVC3 C#.Net web app. I have the below string array.
public static string[] HeaderNamesWbs = new[]
{
WBS_NUMBER,
BOE_TITLE,
SOW_DESCRIPTION,
HARRIS_WIN_THEME,
COST_BOGEY
};
I want to find the Index of a given entry when in another loop. I thought the list would have an IndexOf. I can’t find it. Any ideas?
Well you can use
Array.IndexOf:Or just declare
HeaderNamesWbsas anIList<string>instead – which can still be an array if you want:Note that I’d discourage you from exposing an array as
public static, evenpublic static readonly. You should considerReadOnlyCollection:If you ever want this for
IEnumerable<T>, you could use:(The +1 and -1 are so that it will return -1 for “missing” rather than 0.)