C# 4.0/BCL 4 Series: StructuralComparisons Type
I have been spending quite a bit of time re-focusing and reviewing C# (and some BCL) fundamentals, with an eye to what's different in C# 4.0/BCL 4.0. The reason for this, is though C# 1.0 was so simple in it's day that it only required a 28 page spec, C#3 and 4 have really gotten away from me such that I'm only making average use of 3.0. I'll write a comparison review of the books I have been using, but for my money, the best and definitive book (as it was in 3.0) is C# 4.0 In A Nutshell (Disclaimer: I was a reviewer for V3 of this book and mentioned in the acknowledgements for this edition as well.
So back, to this cool new BCL 4.0 thing. This comes write out of the book on Page 275. As we all know, arrays are reference types, so that the statement arrayb = arraya results in two variables that reference the same array. Simarly, two distinct arrays will always fail an equality test - unless you use a custom equality comparer. Framework 4.0 provides one for the purpose of comparing elements in arrays or tuples which you can access via the StructuralComparisons type:
object[] a1 = {"string", 123, true};
object[] a2 = {"string", 123, true};
Console.WriteLine(a1 == a2); // False
Console.WriteLine(a1.Equals(a2)); // False
IStructuralEquatable se1 = a1;
Console.WriteLine(se1.Equals(a2,
StructuralComparisons.StructuralEqualityComparer));

Pingback from Twitter Trackbacks for Framework 4.0: StructuralComparisons Type : Sam Gentile's Blog (if (DeveloperTask == Communication && OS == Windows) [samgentile.com] on Topsy.com
Pingback from Twitter Trackbacks for Framework 4.0: StructuralComparisons Type : Sam Gentile's Blog (if (DeveloperTask == Communication && OS == Windows) [samgentile.com] on Topsy.com
Pingback from Twitter Trackbacks for Framework 4.0: StructuralComparisons Type : Sam Gentile's Blog (if (DeveloperTask == Communication && OS == Windows) [samgentile.com] on Topsy.com
Might as well make this a series. I mentioned in the first post , "I have been spending quite a bit of time re-focusing and reviewing C# (and some BCL) fundamentals, with an eye to what's different in C# 4.0/BCL 4.0. The reason for this, is though