- 出版社: Addison-Wesley Professional; 1 (2010年3月12日)
- 丛书名: Addison-wesley Microsoft Technology Series
- 平装: 336页
- 语种： 英语
- ISBN: 0321637003
- 条形码: 9780321637000, 0785342637007
- 商品尺寸: 17.9 x 2.2 x 23 cm
- 商品重量: 522 g
- ASIN: 0321637003
- 用户评分: 分享我的评价
- 亚马逊热销商品排名: 图书商品里排第1,179,362名 (查看图书商品销售排行榜)
LINQ to Objects Using C# 4.0: Using and Extending LINQ to Objects and Parallel LINQ (PLINQ) (英语) 平装 – 2010年3月12日
Troy Magennis is a Microsoft C# MVP and a keen traveler who currently works for Travelocity, which manages the travel and leisure websites travelocity.com, lastminute.com, and zuji. As Vice President of Architecture, he leads a talented team of architects spread across four continents, committed to being the traveler’s champion. Technology has always been a passion. After cutting his teeth on early 8-bit personal computers, Troy moved into electronic engineering (assembly language coding), which later led to positions in software application development and architecture for some of the most prominent corporations in automotive, banking, and online commerce. Troy’s first exposure to LINQ was in 2006 when he took a sabbatical to learn it and became hooked, ultimately leading him to publish the popular HookedOnLINQ website.
Foreword . . . x
Preface . . . xii
Acknowledgments . . . xix
About the Author . . . xx
Chapter 1: Introducing LINQ . . . 1
What Is LINQ? . . . 1
The (Almost) Current LINQ Story . . . 3
LINQ Code Makeover–Before and After Code Examples . . . 5
Benefits of LINQ . . . 12
Summary . . . 15
References . . . 15
Chapter 2: Introducing LINQ to Objects . . . 17
LINQ Enabling C# 3.0 Language Enhancements . . . 17
LINQ to Objects Five-Minute Overview . . . 30
Summary . . . 39
References . . . 39
Chapter 3: Writing Basic Queries . . . 41
Query Syntax Style Options . . . 41
How to Filter the Results (Where Clause) . . . 49
How to Change the Return Type (Select Projection) . . . 54
How to Return Elements When the Result Is a Sequence (Select Many) . . . 59
How to Get the Index Position of the Results . . . 61
How to Remove Duplicate Results . . . 62
How to Sort the Results . . . 63
Summary . . . 73
Chapter 4: Grouping and Joining Data . . . 75
How to Group Elements . . . 75
How to Join with Data in Another Sequence . . . 93
Summary . . . 119
Chapter 5: Standard Query Operators . . . 121
The Built-In Operators . . . 121
Aggregation Operators–Working with Numbers . . . 123
Conversion Operators–Changing Types . . . 131
Element Operators . . . 144
Equality Operator–SequenceEqual . . . 153
Generation Operators–Generating Sequences of Data . . . 155
Merging Operators . . . 159
Partitioning Operators–Skipping and Taking Elements . . . 160
Quantifier Operators–All, Any, and Contains . . . 164
Summary . . . 171
Chapter 6: Working with Set Data . . . 173
Introduction . . . 173
The LINQ Set Operators . . . 174
The HashSet<T> Class . . . 185
Summary . . . 192
Chapter 7: Extending LINQ to Objects . . . 195
Writing a New Query Operator . . . 195
Writing a Single Element Operator . . . 196
Writing a Sequence Operator . . . 208
Writing an Aggregate Operator . . . 216
Writing a Grouping Operator . . . 222
Summary . . . 232
Chapter 8: C# 4.0 Features . . . 233
Evolution of C# . . . 233
Optional Parameters and Named Arguments . . . 234
Dynamic Typing . . . 243
COM-Interop and LINQ . . . 251
Summary . . . 260
References . . . 260
Chapter 9: Parallel LINQ to Objects . . . 261
Parallel Programming Drivers . . . 261
Multi-Threading Versus Code Parallelism . . . 264
Parallelism Expectations, Hindrances, and Blockers . . . 267
LINQ Data Parallelism . . . 271
Writing Parallel LINQ Operators . . . 289
Summary . . . 301
References . . . 301
Glossary . . . 303
Index . . . 307
|5 星 (0%)|
|4 星 (0%)|
|3 星 (0%)|
|2 星 (0%)|
|1 星 (0%)|
The Kindle version is a complete mess. I know people find it annoying when reviewers drop the rating because of the format, but when you pay good money for a product, you expect professional results. The biggest issue is that all of the code samples look as if they were scanned images that were then OCR'd in. Many of the code samples look incredibly washed out, blurry and are almost impossible to read. Also, there are a few errors that occurred due to this scanning process, such as the wrong braces being displayed, some symbols are changed (what would be a less-than sign might show in the code sample as an equals sign for instance). It's really too bad. Do NOT buy this on Kindle, it is junk.
If the publishers fix this problem I'll happily bring my review up to 5 stars, but until then it remains at 2. I suffered way too many headaches trying to decipher this mess.
For the student: Does the following make sense to you? "The zero-based index position can be passed into a lambda expression predicate by assigning a variable name as the second argument..." The author will build to such statements, but if this is completely Greek to you, I'd concentrate on more general C# studies first.
For the pro: Magennis won't make you work very hard, so the book will fly by quickly, but in the end he'll reward you with a lot more depth than you would first imagine. This is not just a surface review of LINQ, but a great introduction that goes into the C# compliler far enough to make the C# programmer feel grounded in not just the use of LINQ, but also in the technology as a study unto itself.
Magennis is a (if not the) LINQ fan, and his love for the technology will rub off, but he never tries to convince you that it replaces database querying. In fact, by sticking to LINQ for Objects in particular, really the book is more about dictionary/collection/list/array manipulation than datasources, although both text file munching and COM interop with Excel as datasources are handled (and I think it's assumed that once you realize you cannot in general use a datareader for LINQ, you can marshal your data into memory by whatever other means you've been using, with some short comment on how to partition data reads for large data sources).
Another strong trait of the text is how Magennis aptly compares C# 2.0 ways of doing things with C# 4.0, not for historical reasons, but because those comparisons really demonstrate what the newer technology must be doing behind the scenes. This is not an obvious set of "least pairs discrimation" so I appluad Magennis on the great didactic results it provides.
I do wish that Magennis had added a final chapter exploring expression trees with the same skill he applied to PLINQ, even if that would have been moving a little off theme; it just seems like even though this text isn't about transforming LINQ queries for use in non-memory sources, nonetheless somehow the expression tree belongs to the story...or maybe I'd just like to pick such an expert's mind on the topic in any case.
The pro will not be burdened or disappointed. Good fun.
The book is about using LINQ, and PLINQ to change how you query objects and collections in RAM. This is not a database book. You can use any of the methods in this book to work with just about any collection in .Net. Some of the same concepts work with databases like Entity Framework and LINQ to EF, but that is not the core of this book.
A few of the chapters that really stand out to me:
Chapter 7 covers extending LINQ to Objects and has a lot of fantstic nuggets in here. I didn't know you could write your own grouping operator in LINQ until I read this chapter.
Chapter 9 Parallel LINQ to Objects - Nice concise explanations of parallel problems and how to solve them using PLINQ. There is definitely room to expand this section with more advanced topics, but the coverage here is more than enough to get you running and thirst for the in depth discussions on MSDN.
I recommend the book for anyone trying to get their head around LINQ to Objects, and possibly just more advanced LINQ concepts in general.
Of course I recommend you go grab a copy of LINQPAD ([..] ) to write queries in and execute without needing a solution in Visual Studio. I found Linqpad to be amazing for productivity of testing LINQ queries.