HomeCSharpC# Error CS0677 – ‘{0}’: a volatile field cannot be of the type ‘{1}’

C# Error CS0677 – ‘{0}’: a volatile field cannot be of the type ‘{1}’

C# Error

CS0677 – ‘{0}’: a volatile field cannot be of the type ‘{1}’

Reason for the Error & Solution

‘variable’: a volatile field cannot be of the type ‘type’

Fields declared with the volatile keyword must be one of the following types:

  • Any reference type

  • Any pointer type (in an unsafe context)

  • The types sbyte, byte, short, ushort, int, uint, char, float, bool

  • Enum types based on any of the above types

The following sample generates CS0677:

// CS0677.cs  
class TestClass  
{  
   private volatile long i;   // CS0677  
  
   public static void Main()  
   {  
   }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...