February 2007

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28      
Blog powered by TypePad

« Array vs ArrayList | Main | Power Collections »

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83424ed4953ef00d8348de61169e2

Listed below are links to weblogs that reference Getting the Array:

Comments

Joe G.

So is there a nifty way to do this in reverse? E.g., can I take a LabVIEW array and stuff it into an ArrayList with a similar technique?

Brian Tyler

Yes and no. Using the other VI in that vi.lib library, To Object.vi, you can convert a LV array to a .NET array explicitly. What comes out of that VI, however, is System.Object.

To be able to pass it into the constructor of an ArrayList, you must first cast it to the ICollection interface. This is where the bug in LV 7 bites you - LV 7 doesn't support casting to interfaces in most cases. So you need to either create a helper assembly to do the cast for you or upgrade to Constellation when it ships.

So basically the answer is a qualified yes!

Mark Smith

Is there a general solution to get the elements of a collection? Specifically, I want to use some classes in the System.XML namespace to get and replace some document elements. The method returns a nodeList. So, is this practical to do straight from LabVIEW or should I wrap the functionality in a DLL that returns an array to LabVIEW?

Mark

Brian Tyler

I'm assuming you're talking about an XmlNodeList. The problem here is that it only supports the IEnumerable interface. This means converting it to an array in LabVIEW can be expensive if you have a large number of elements. You can always converts an enumerable into a LV array, one element at a time, but you can see the cost as it grows in size.

My recommendation to you and everyone else is

1. If you can write the .NET code, and it's easy to encapsulate into a handy routine that can be reused, then do that and return an array.

2. If you can't, or there would be dozens of these little .NET routines, consider not converting to a LV array. Perhaps you should provide accessor VIs, or create a LabVIEW class (8.20 and on feature).

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment