C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Simple Syntax Question
Sean Doyle
post Jun 29 2009, 10:50 AM
Post #1


New Member
*

Group: Members
Posts: 1
Joined: 29-June 09
Member No.: 18,920



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.
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jun 29 2009, 04:32 PM
Post #2


Advanced Member
******

Group: Members
Posts: 207
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 7th November 2009 - 05:07 PM