What is the function of the SizeConst of the array of MarshalAs
This article mainly introduces "what is the function of the SizeConst of the array of MarshalAs". In the daily operation, I believe that many people have doubts about the role of the SizeConst of the array of MarshalAs. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the use of the SizeConst of the array of MarshalAs?" Next, please follow the editor to study!
[StructLayout (LayoutKind.Sequential)] class CLS {public int id; public float value; [MarshalAs (UnmanagedType.ByValArray,SizeConst=10,ArraySubType=UnmanagedType.Struct)] public Point [] ps; [MarshalAs (UnmanagedType.LPStr)] public string msg; [MarshalAs (UnmanagedType.ByValArray,SizeConst=5,ArraySubType=UnmanagedType.LPStr)] public string [] msgs } Console.WriteLine ("Number of bytes needed by a CLS object: {0}", Marshal.SizeOf (typeof (CLS); CLS cls = new CLS (); string [] s = new string [10]; for (int I = 0 X I < 10 x I +) {s [I] = "demo" + I;} cls.msgs = s For (int iTuno Bandi)