I have been looking over the technical preview of Whidbey and have found the documentation to be lacking for many of the new features in C#. For example, in Whidbey, it is now possible to have fixed arrays at least inside structs. This was mentioned at the C# talk at PDC. These arrays are stored inline, and, I believe, only work with value types. Since length information is omitted, no range checking is performed; hence, code that uses this feature must be declared unsafe. This feature is mainly provided to support calls to Win32 that utilize inlined arrays, but the CLR has other ways to accomplish this.
unsafe class Program { unsafe struct FixedStruct { public fixed int array[10]; public int overflow; } static void Main(string[] args) { FixedStruct fixedStruct = new FixedStruct(); fixedStruct.array[10] = 2; fixedStruct.array[10] = 3; Console.WriteLine(fixedStruct.overflow); Console.ReadLine(); } }
Comments