嵌套在lambda表达式中的方法的参数在调用时更改

时间:2016-06-01 19:33:28

标签: c# lambda

我有以下内容,它在节点图系统初始化时运行,用于节点的每个端口;

<select class="week-selector">
      <option value="" disabled selected>Week</option>
      <option value="Week1">Week 1</option>
      <option value="Week2">Week 2</option>
      <option value="Week3">Week 3</option>
      <option value="Week4">Week 4</option>
      <option value="Week5">Week 5</option>
</select>

如果我在for循环中打印<form class="input-field col s6 card-selector"> <select multiple"> <option value="" disabled selected>Select Students</option> {{#each StudentList1}} <option value= '{{FullName}}'>{{formatName FullName}} ({{Level}}) {{RoomWk2}}</option> {{/each}} </select> </form> ,当我有3个项目时,我会按预期得到 private void Initialize() { // stats.Length return 3; for (int i = 0; i < stats.Length; i++) stats[i].Initialize(this, () => GetStats(i)); } private void GetStats(int index) { // Issue; index returns 3 }

不知何故,如果我在i打印0, 1, 2,我会index

我只是迷失在这里,嵌套在lambda中的方法中的值类型参数如何改变值?我做了些蠢事吗?

0 个答案:

没有答案