0

I'm a Python programmer and VB.NET newbie converting an application from Python to VB.NET (3.5).

In Python, I have a function which returns a list of tuples which I run on two datasets with results like this:

data1 = [(1,"a",2),(5,"c",7)...]
data2 = [(1,"a",2),(5,"x",7)...]

Then I want to check if the two data sets are identical. In Python I check for equality like this:

"Equal" if data1 == data2 else "Not Equal"

I want to know the easiest way to structure the data in VB.NET.

It looks like the right data structure for each data set in VB.NET is a List(of Something).

Should I create a Class to hold each data item, or is there a simpler way? If I do, will I need a custom way to decide if two instances hold the same data?

What is the easiest way to compare the two data sets for equality?

user483263
  • 55
  • 1
  • 9

2 Answers2

1

You can use the Tuple(Of T1, T2, T3) generic type, or make your own class.
Either way, you'll need to create an IEqualityComparer(Of T) for the class; you can then check whether set1.SequenceEqual(set2, New MyComparer()).

If you create your own class, you can override Equals() and GetHashCode() instead of creating an IEqualityComparer.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Thanks. I looked this up and apparently Tuple is new in .NET 4.0. I've updated to indicate I'm using .NET 3.5. – user483263 Jan 14 '11 at 15:33
  • Then you'll need to make your own class. If the items live entirely within a function, you can also use an anonymous type. (In which case you wouldn't need an `IEqualityComparer`, since anonymous types implement `Equals` and `GetHashCode`. – SLaks Jan 14 '11 at 15:36
1

Personally, I'd create a small class to hold each item, then use List(Of ItemType) to track the lists. As for comparing the two lists for equality, see here Comparing two collections for equality irrespective of the order of items in them

Community
  • 1
  • 1
DarinH
  • 4,868
  • 2
  • 22
  • 32