C# Error CS1642 – Fixed size buffer fields may only be members of structs

C# Error

CS1642 – Fixed size buffer fields may only be members of structs

Reason for the Error & Solution

Fixed size buffer fields may only be members of structs.

This error occurs if you use a fixed size buffer field in a class, instead of a struct. To resolve this error, change the class to a struct or declare the field as an ordinary array.

Example

The following sample generates CS1642.

// CS1642.cs  
// compile with: /unsafe /target:library  
unsafe class C  
{  
   fixed int a[10];   // CS1642  
}  
  
unsafe struct D  
{  
    fixed int a[10];  
}  
  
unsafe class E  
{  
   public int[] a = null;  
}  

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...