Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

How to define a Class with fixed size array of sub structures

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shofu_au@yahoo.com.au - 27 Jun 2007 09:31 GMT
Hi Group,

I am trying to define a class that has a fixed size array of a
structure containing a fixed size array of a structure.

I am using System.Runtime.InteropServices and trying to define the
fixed size using [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]

In the attached console application example when I try to address the
fields in the class I get an execption.
Also when I try to examine the sub structures in the debugger I get
NULL.

So I assume I need to use new to create the fields - I have tried
several combinations without any success.

Does anyone konw what I am doing wrong in this example?

Thanks

Mark

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ArrayofStruct
{
   class Program
   {
       static void Main(string[] args)
       {
           toplevel firstlevel = new toplevel();

           // firstlevel.

firstlevel.level1[1].subelevel1_array[1].sublevel2_array[1] = 0;
       }
   }

   public struct sublevel2 //Sublevel 2 struct containing array 10 of
UInt16
   {
       public UInt16 sublevel2_field1;
       [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
       public UInt16[] sublevel2_array;
   }

   public struct sublevel1  //Sublevel 1 struct containing array of
10 of level2 struct
   {
       public UInt16 sublevel1_field1;
       [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
       public sublevel2[] subelevel1_array;
   }

   public class toplevel  //Toplevel Class containing array 10 of
level1 struct
   {
       public UInt32 field1;
       [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
       public sublevel1 [] level1;
   }
}
Shine Xavier - 27 Jun 2007 14:41 GMT
This link should help you -

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1759108&SiteID=1

Thanks -

> Hi Group,
>
[quoted text clipped - 61 lines]
>    }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.