This documentation is archived and is not being maintained.

Compiler Error CS0676

Visual Studio .NET 2003

Cannot pass volatile field 'variable' as ref or out, or take its address

A variable that is marked with the volatile keyword cannot be passed to a ref or out parameter.

The following sample generates CS0676:

// CS0676.cs
using System;

class TestClass
   private volatile int i;

   public void TestVolatile(ref int ii)

   public static void Main()
      TestClass x = new TestClass();
      x.TestVolatile(ref x.i);   // CS0676 don't pass volatile value as ref