我使用以下代码
发生此错误:
尝试读取或写入受保护的内存.这通常表明其他内存已损坏.尝试读取或写入受保护的内存.这通常表明其他内存已损坏.
Public Class FormRegEnumValue
Private Const ERROR_SUCCESS = 0&
Private Const ERROR_NO_MORE_ITEMS = 259&
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const REG_EXPAND_SZ = 2
Private Const REG_SZ = 1
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, ByVal lpcbValueName As Long, ByVal lpReserved As Long, ByVal lpType As Long, ByVal lpData As Object, ByVal lpcbData As …Run Code Online (Sandbox Code Playgroud) 以下为什么不是相同的答案?
正常编码:
long sum = 0;
for (long i = 1; i <= 10; i++)
{
long result = 1;
for (long j = 1; j <= i; j++)
{
result = result*j;
}
sum = sum + result;
}
Run Code Online (Sandbox Code Playgroud)
并行编码:
long sum = 0;
Parallel.For(1, 10, delegate(int i)
{
long result = 1;
Parallel.For(1, i, delegate(int j)
{
result = result*j;
});
sum = sum + result;
});
Run Code Online (Sandbox Code Playgroud)
请告诉我正确的方法
for (long i = 1; i <= 5; i++)
{ …Run Code Online (Sandbox Code Playgroud)