Saturday, August 24, 2013

Fix array sizes within unsafe C# methods?

There is a way to fix the size of an array at its declaration after all, but in involves the unsafe keyword and I cannot get an example to work. I read of this in C# 4.0 in a Nutshell.

using System.Runtime.InteropServices;
namespace Fun.Core
{
   [StructLayout (LayoutKind.Sequential)]
   unsafe struct Testing
   {
      public fixed float whatever [6];
   }
}

No comments:

Post a Comment