使用CObj或DirectCast包裝參數將關閉編譯器,但該值仍未寫入。如何使用帶有Option Strict On的引用類型的Thread.VolatileWrite?
Option Strict On
Imports System.Threading
Module Module1
Dim str As String
Sub Main()
Thread.VolatileWrite(str, "HELLO") ' Compiler error.
Thread.VolatileWrite(CObj(str), "HELLO") ' Fails silently.
Thread.VolatileWrite(DirectCast(str), "HELLO") ' Fails silently.
Console.WriteLine(str)
End Sub
End Module
代碼示例真的有幫助... – 2011-04-20 14:38:26