Get value from array if not out of bounds
Why not use an Array
?
public object GetNamedParametersFrom(GenericObject genericObject)
{
string[] namesFromLists = new string[genericObject.ListOfThings.Count];
for (int i = 0; i < genericObject.ListOfThings.Count; i++)
{
namesFromLists[i] = genericObject.ListOfThings[i].Name;
}
return namesFromLists; //As you are returning an `object`, you can return `resources` array directly from this method
}
Why not use the built-in ElementAtOrDefault
method from Linq?
string[] names =
{ "Hartono, Tommy", "Adams, Terry", "Andersen, Henriette Thaulow",
"Hedlund, Magnus", "Ito, Shu" };
int index = 20;
string name = names.ElementAtOrDefault(index);