Re: Array vs List<>

Simon Robinson <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <LISTSERV%[email protected]>
I wondered if someone would say something like that :)

In this situation I typically have two arrays

	classA [] a = whatever1();
	classB [] b = whatever2(); // same size as a

and I need to do this:

// no way to do this without indexed access
for (int i=0 ; i<a.Length ; i++)
{
	ProcessElements(a[i], b[i]);
}

The more complete object model solution would probably be to define something like

struct A_and_B
{
	A a;
	B b;
}

Allowing me to instead iterate through a single array of type A_and_B[] without worrying about indexes.

While that is a possible solution, I'm dubious about whether that leads to better or clearer code, since you've now got a whole additional type (and possibly quite an artificial, nonintuitive, one) that's there purely for use in a single method.

Simon

On Wed, 5 Nov 2008 22:27:28 -0000, Chris Anderson 
>FWIW that smells a lot of an incomplete object model.
>If the objects in the array/list were design-complete, you wouldn't 
>need
>to attribute additional data in a parallel array/list.

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.