Printable Version of Topic

Click here to view this topic in its original format

O'Reilly Forums _ C# 3.0 in a Nutshell _ Simple Syntax Question

Posted by: Sean Doyle Jun 29 2009, 10:50 AM

In the example for Chapter 8/Projection Strategies/Object Initializers - why are the {} unbalanced?

On my machine (which runs the example just fine) there is a "}" following temp.Dump(); there is no "}" at the end of the class definition for TempProjectionItem. Why is this?

I'm guessing that there is an implicit "{" at the start of the statements and "}" at the end. It just looks odd.

Posted by: JoeAlbahari Jun 29 2009, 04:32 PM

Good question!

This is because that example defines an extension method. Ordinarily, when you define classes in LINQPad, they're nested classes and so can't be static and so can't contain extension methods. This trick lets you create a nonnested class.

I hope to find some way around this in future versions - so you'll be able to define extensions methods without the unmatched brackets.

Joe

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)