VB.net更新For Each循环中的List变量

时间:2016-05-30 20:54:59

标签: vb.net loops for-loop each

web.config

问题在这里开始vvv

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="ResearchClub" connectionString="Data Source=PSYCOZ;Initial Catalog=ResearchClub;Integrated Security=True"/>
  </connectionStrings>

  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>

    <authentication mode="Forms"/>

    <membership>
      <providers>
        <clear/>
        <remove name="ResearchClubMembershipProvider"/>
        <add name="ResearchClubMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ResearchClub"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
             applicationName="/"/>
      </providers>
    </membership>

  </system.web>

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

问题在这里结束^^^

Dim aProductos As List(Of Producto)
Dim aRegistros As New List(Of Registro)
Dim selectedProd As New Producto

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'Add to cart
    Dim insert As Boolean = True

问题是我更新“reg”但是当循环结束时reg没有更新列表中的值

提前致谢:S

1 个答案:

答案 0 :(得分:1)

您可以使用整数来指定列表中的位置,而不是使用For Each

For x = 0 to aRegistros.Count -1
  Dim reg = aRegistros(x)
  Dim r As New Registro
  r.id_prod = reg.id_prod
  r.cantidad = reg.cantidad + Integer.Parse(nudUni.Value.ToString)
  aRegistros(x) = r
  insert = False
Next