Ayende @ Rahien

Unnatural acts on source code

Playing with Orcas

As usual, just a set of random impressions:

  • Anonymous types are annoyingly limited. You can't define arrays of anonymous types, for instnace, which can open up more options for intent revealing code.
  • Linq seems to be heavily based around the idea of Expression, a lot of the stuff that is going on there revolves around Expression and operation on Expressions.
  • Here is a new way to assert that a collection contains all the items that it should:
    Assert.AreEqual(3, list.Intersect(new string[]{"ayende","rahien","bar"}).ToList().Count);
  • I am annoyed that this doesn't work, though:
    Assert.AreEqual(3, list.Intersect({"ayende","rahien","bar"}).ToList().Count);
    Shouldn't this be handled by the collection initializer?

 

Comments

scottgu
03/16/2007 03:53 AM by
scottgu

If Intersect is an extension method, you could define it like so:

public static bool Intersect(this T value, params T[] values) {

 // do something

}

Assuming is a string, you could then write:

list.Intersect("scott", "guthrie")

Hope this helps,

Scott

Daniel Grunwald
03/16/2007 11:41 AM by
Daniel Grunwald

I didn't try it, but I've read about the syntax new [] { "a", "b" }

So you don't have to write "string" anymore. This should allow creating arrays of anonymous types.

Sergio
03/16/2007 12:19 PM by
Sergio

For your last bullet point, ScottGu answered over at his blog:

http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx#1979012

dru
03/16/2007 04:17 PM by
dru

man I hope that the new

[] {"a","b"} works. I am so jealous of python and rubys array literals.

-d

Comments have been closed on this topic.