// 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 { [StructLayout(LayoutKind.Sequential)] public struct S { public int Iv1; public int Iv2; public string Sv1; public string Sv2; } public class Program { [DllImport(@"C:\work\demo.dll")] public extern static void X2(ref S s); public static void Main(string[] args) { S s; s.Iv1 = 123; s.Iv2 = 0; s.Sv1 = "ABC"; s.Sv2 = ""; string sav = s.Sv2; //Console.WriteLine(object.ReferenceEquals(sav, s.Sv2)); X2(ref s); Console.WriteLine(s.Iv2 + " " + s.Sv2); //Console.WriteLine(object.ReferenceEquals(sav, s.Sv2)); } } }