TechyMedia

A .NET Technology blog | .NET,C# Progamming,C# tutorials,WPF WCF|Software Engineer

NAVIGATION - SEARCH

C# Fixed Size Buffer

In .NET normally arrays are reference types and any array declared as part of a structure doesn't physically exist inside the C# struct.Hence declaring a C++ style fixed-size structure was difficult in earlier versions of c#.In C# 2.0, it's now possible declare arrays in structure as fixed-sized inside unsafe code blocks.

In .NET normally arrays are reference types and any array declared as part of a structure doesn't physically exist inside the struct.Only a reference to the array is placed inside the structure, which points to the original location of the array on the heap.Hence declaring a C++ style  fixed-size structure was difficult in earlier versions of C#.


In C# 2.0, it's now possible declare arrays in structure as fixed-sized inside unsafe code blocks. Fixed arrays will typically be part of a structure that's passed to a native API.
public unsafe struct CharArray

 

{
     public fixed char fixSizeBuffer[128];
}


Covariance & Contravariance

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading