ITPub博客

首页 > 应用开发 > > 遍历中不可以对变量进行操作吗

遍历中不可以对变量进行操作吗

作者:netroop 时间:2019-08-12 14:13:52 0 删除 编辑

foreach(int i in arr){

Console.WriteLine(i);

i=i+5;

}

报错:

Microsoft (R) Visual C# Compiler version 4.0.30319.34209

for Microsoft (R) .NET Framework 4.5

Copyright (C) Microsoft Corporation. All rights reserved.

c:\program\bb.cs(9,4): error CS1656: Cannot assign to 'i' because it is a 'foreach iteration variable'

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4741/viewspace-3124681/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-25

  • 博文量
    152
  • 访问量
    1068