is there something equivalent to 'Address of' or offset operator in .net?
- by Gio
We have nested stuctures as such, used as an interface for some device drivers. On occasion we have to update individual elements. An 'address of' operator would be helpful, but an 'offset' function or operator is what I'm really looking for, but not sure how to go about it. In other words, how far is structureN.elementX away from the start of the structure in bytes?
[StructLayout(LayoutKind.Sequential)]
public struct s1
{
UInt16 elem1;
UInt16 elem2;
UInt16 elem3;
}
[StructLayout(LayoutKind.Sequential)]
public struct s2
{
UInt16 elem1;
UInt16 elem2;
UInt16 elem3;
}
[StructLayout(LayoutKind.Sequential)]
public struct driver
{
public S1 s1;
public S2 s2;
}
For instance we need to send the device driver some data to update driver.s1.elem3, by way of providing an offset address, data block and length. We would update our local copy, then call the device api with the afore mentioned data. Not sure I have to do this with 'unsafe' method calls. Any help?