Maybe this is by design, but could somebody explain why it behaves like this?
I'm writing an android app with Xamarin in Visual Studio 2015.
I downloaded this example, and was trying to make it a little more simpler to use.
Here is the method being called by my code, which works fine.
private List<Android.Support.V4.App.Fragment> _fragmentList = new List<Android.Support.V4.App.Fragment>();
public void AddFragmentView(Func<LayoutInflater, ViewGroup, Bundle, View> view)
{
_fragmentList.Add(new GenericViewPagerFragment(view));
}
The next method works fine, as expected. I'm passing it a list of numbers associated with my layout files.
public void AddViewsToFragmentList(List<int> views)
{
for(int j=0; j<views.Count; j++)
{
int viewIndex = views[j];
AddFragmentView((i, v, b) =>
{
var view = i.Inflate(viewIndex, v, false);
return view;
}
);
}
}
Now, if I don't create the viewIndex variable first, but simply pass it that index, it is giving me an index out of range error.
public void AddViewsToFragmentList(List<int> views)
{
for(int j=0; j<views.Count; j++)
{
AddFragmentView((i, v, b) =>
{
var view = i.Inflate(views[j], v, false); //errors here when it gets to 3, which it should never reach
return view;
}
);
}
}
Is there some reason why even though I told my loop to stop when it reaches the list count that it is still trying to run the code in my loop? Once j becomes 3, it should stop the loop and never get to that function, right?