Initializing Array as Object Property

I'm having problems with a null reference in VB.NET and haven't been able to find the proper way to initialize the array of objects that are a property of another object.  In C#, you can successfully do the following:

request.Items = new BTUnit[] { unit1, unit2 };

However, I don't know how to do this in VB.  I cannot set the individual values of the array as follows because the array hasn't been initialized:

request.items(0) = unit1
request.items(1) = unit2

Calling request.items.initialize results in a null references.  I also can't use request.items.createinstance because "BTUnit" is not a system.type.

Any ideas?
CUOL-MISAsked:
Who is Participating?
 
lazyberezovskyCommented:
Any class in .Net (not matter C# or VB.NET) is inherited from System.Object.
See: http://msdn.microsoft.com/en-us/library/0zw9e48h(VS.71).aspx

So, you can be sure there is other reason.
Maybe your request object is set to null?
0
 
lazyberezovskyCommented:
Code below should work
request.Items = New BTUnit() {unit1, unit2}

Open in new window

0
 
CUOL-MISAuthor Commented:
Yes, I thought the same thing.  I tried that syntax previously but the issue is with the class itself.  In the VB app, the class is a partial class that is defined with MustInherit.  In the C# app, the partial class is defined as Abstract.  For some reason, the abstract class in C# inherits the Object class but the mustinherit class doesn't inherit Object in VB.  The class is from a web reference, so I don't know why VS 2005 would treat it differently based on the language.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.