I'm using a prefab of a button and creating a number of buttons at runtime. While adding listners from script(C#) I can't add value from a list using index (The int field in the title).

```
for (int i=0; i<messageList.Count; i++) {
        Button msgBtnObj = Instantiate (msgListPrefabObj) as Button;
        MessageListPrefabScript msgListPrefabScriptRef = msgBtnObj.GetComponent<MessageListPrefabScript> ();
        msgListPrefabScriptRef.msgText.text = msglistToShow[i].msgFieldText;  //here i works
        msgBtnObj.transform.SetParent (msglistPanel);
        msgBtnObj.name = "msgbtn_" + msglistToShow [i].msgFieldText;  //here i works
        msgBtnObj.GetComponent<Button> ().onClick.AddListener(delegate { clickedOnMsg(messageList [i]); });  //here i doesn't work

    }

```

The last line gives me a ArgumentOutOfRangeException. Now if I use 1,2,3 etc. it works. But how can I use a variable, e.g. the loop iterator i ?

This is the stacktrace of the exception,

```
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.String].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
CreateMsgListScript+<PopulateMsglist>c__AnonStorey9.<>m__1 () (at   Assets/CreateMsgListScript.cs:74)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at /home/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:137)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at /home/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:601)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at /home/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:743)
UnityEngine.Events.UnityEvent.Invoke () (at /home/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
UnityEngine.UI.Button.Press () (at /home/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick  (UnityEngine.EventSystems.PointerEventData eventData) (at /home/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /home/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /home/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()

```