// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Runtime.InteropServices; namespace E { public struct S { private int v,origv; public S(int v) { this.v = v; this.origv = v; } public override string ToString() { return v.ToString() + "=" + origv.ToString(); } } public class C { public S s; } public class Program { [DllImport("msvcrt.dll")] public static extern void memcpy(IntPtr dst, IntPtr src, int len); public static void Main(string[] args) { C o = new C(); o.s = new S(1); Console.WriteLine(o.s); C o2 = new C(); o2.s = new S(2); Console.WriteLine(o2.s); unsafe { fixed(S *ps = &o.s) { fixed(S *ps2 = &o2.s) { memcpy((IntPtr)ps, (IntPtr)ps2, 4); } } } Console.WriteLine(o.s); Console.WriteLine(o2.s); } } }