<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bookcold&#039;s Blog &#187; .Net</title>
	<atom:link href="http://bookcold.com/tag/net/feed" rel="self" type="application/rss+xml" />
	<link>http://bookcold.com</link>
	<description>Just for pleasure</description>
	<lastBuildDate>Thu, 09 Sep 2010 06:49:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>《CLR via C#, Third Edition》第三版</title>
		<link>http://bookcold.com/2010/02/279</link>
		<comments>http://bookcold.com/2010/02/279#comments</comments>
		<pubDate>Sat, 20 Feb 2010 03:41:10 +0000</pubDate>
		<dc:creator>bookcold</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://bookcold.com/2010/02/20/279/</guid>
		<description><![CDATA[<p>特大喜讯！！</p> <p>下载地址：http://www.ppurl.com/2010/02/clr-via-csharp-third-edition.html</p> &#160; <p> 主要内容： <p>Part I CLR Basics</p> <p>1 The CLR’s Execution Model . 1</p> <p>Compiling Source Code into Managed Modules . 1</p> <p>Combining Managed Modules into Assemblies 5</p> <p>Loading the Common Language Runtime 6</p> <p>Executing Your Assembly’s Code 9</p> <p>IL and Verification 15</p> <p>Unsafe Code 16</p> <p>The Native Code Generator Tool: NGen.exe [...]]]></description>
			<content:encoded><![CDATA[<p>特大喜讯！！</p>
<p>下载地址：<a href="http://www.ppurl.com/2010/02/clr-via-csharp-third-edition.html">http://www.ppurl.com/2010/02/clr-via-csharp-third-edition.html</a></p>
<h3>&#160;</h3>
<p> <span id="more-279"></span><br />
<h3>主要内容：</h3>
<p>Part I <strong>CLR Basics</strong></p>
<p><strong>1 </strong>The CLR’s Execution Model . 1</p>
<p>Compiling Source Code into Managed Modules . 1</p>
<p>Combining Managed Modules into Assemblies 5</p>
<p>Loading the Common Language Runtime 6</p>
<p>Executing Your Assembly’s Code 9</p>
<p>IL and Verification 15</p>
<p>Unsafe Code 16</p>
<p>The Native Code Generator Tool: NGen.exe . 18</p>
<p>The Framework Class Library . 20</p>
<p>The Common Type System 22</p>
<p>The Common Language Specification . 25</p>
<p>Interoperability with Unmanaged Code 29</p>
<p><strong>2 </strong>Building, Packaging, Deploying, and Administering Applications</p>
<p>and Types 31</p>
<p>.NET Framework Deployment Goals 32</p>
<p>Building Types into a Module 33</p>
<p>Response Files . 34</p>
<p>A Brief Look at Metadata . 36</p>
<p>Combining Modules to Form an Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43</p>
<p>Adding Assemblies to a Project by Using the Visual Studio IDE 49</p>
<p>Using the Assembly Linker 50</p>
<p>Adding Resource Files to an Assembly . 52</p>
<p>Assembly Version Resource Information . 53</p>
<p>Version Numbers 57</p>
<p>Culture . 58</p>
<p>Simple Application Deployment (Privately Deployed Assemblies) . 59</p>
<p>Simple Administrative Control (Configuration) 61</p>
<p><strong>3 </strong>Shared Assemblies and Strongly Named Assemblies . 65</p>
<p>Two Kinds of Assemblies, Two Kinds of Deployment 66</p>
<p>Giving an Assembly a Strong Name . 67</p>
<p>The Global Assembly Cache 73</p>
<p>Building an Assembly That References a Strongly Named Assembly 75</p>
<p>Strongly Named Assemblies Are Tamper-Resistant 76</p>
<p>Delayed Signing . 77</p>
<p>Privately Deploying Strongly Named Assemblies 80</p>
<p>How the Runtime Resolves Type References 81</p>
<p>Advanced Administrative Control (Configuration) 84</p>
<p>Publisher Policy Control 87</p>
<p>Part II <strong>Designing Types</strong></p>
<p><strong>4 </strong>Type Fundamentals 91</p>
<p>All Types Are Derived from System.Object . 91</p>
<p>Casting Between Types . 93</p>
<p>Casting with the C# is and as Operators . 95</p>
<p>Namespaces and Assemblies . 97</p>
<p>How Things Relate at Runtime 102</p>
<p><strong>5 </strong>Primitive, Reference, and Value Types . 113</p>
<p>Programming Language Primitive Types 113</p>
<p>Checked and Unchecked Primitive Type Operations . 117</p>
<p>Reference Types and Value Types . 121</p>
<p>Boxing and Unboxing Value Types . 127</p>
<p>Changing Fields in a Boxed Value Type by Using Interfaces (and Why You</p>
<p>Shouldn’t Do This) . 140</p>
<p>Object Equality and Identity 143</p>
<p>Object Hash Codes 146</p>
<p>The dynamic Primitive Type 148</p>
<p><strong>6 </strong>Type and Member Basics . 155</p>
<p>The Different Kinds of Type Members . 155</p>
<p>Type Visibility 158</p>
<p>Friend Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159</p>
<p>Member Accessibility 160</p>
<p>Static Classes . 162</p>
<p>Partial Classes, Structures, and Interfaces . 164</p>
<p>Components, Polymorphism, and Versioning 165</p>
<p>How the CLR Calls Virtual Methods, Properties, and Events 167</p>
<p>Using Type Visibility and Member Accessibility Intelligently . 172</p>
<p>Dealing with Virtual Methods When Versioning Types . . . . . . . . . . . . . . . . . . . . .175</p>
<p><strong>7 </strong>Constants and Fields 181</p>
<p>Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .181</p>
<p>Fields 183</p>
<p><strong>8 </strong>Methods . 187</p>
<p>Instance Constructors and Classes (Reference Types) . 187</p>
<p>Instance Constructors and Structures (Value Types) . 191</p>
<p>Type Constructors 194</p>
<p>Type Constructor Performance 198</p>
<p>Operator Overload Methods . 200</p>
<p>Operators and Programming Language Interoperability . 203</p>
<p>Conversion Operator Methods 204</p>
<p>Extension Methods 207</p>
<p>Rules and Guidelines 210</p>
<p>Extending Various Types with Extension Methods 211</p>
<p>The Extension Attribute 213</p>
<p>Partial Methods 213</p>
<p>Rules and Guidelines 216</p>
<p><strong>9 </strong>Parameters . 219</p>
<p>Optional and Named Parameters . 219</p>
<p>Rules and Guidelines 220</p>
<p>The DefaultParameterValue and Optional Attributes 222</p>
<p>Implicitly Typed Local Variables 223</p>
<p>Passing Parameters by Reference to a Method 225</p>
<p>Passing a Variable Number of Arguments to a Method . 231</p>
<p>Parameter and Return Type Guidelines . 233</p>
<p>Const-ness 235</p>
<p><strong>10 </strong>Properties 237</p>
<p>Parameterless Properties 237</p>
<p>Automatically Implemented Properties . 241</p>
<p>Defining Properties Intelligently 242</p>
<p>Object and Collection Initializers 245</p>
<p>Anonymous Types 247</p>
<p>The System.Tuple Type 250</p>
<p>Parameterful Properties . 252</p>
<p>The Performance of Calling Property Accessor Methods 257</p>
<p>Property Accessor Accessibility . 258</p>
<p>Generic Property Accessor Methods 258</p>
<p><strong>11 </strong>Events . 259</p>
<p>Designing a Type That Exposes an Event 260</p>
<p>Step #1: Define a type that will hold any additional information</p>
<p>that should be sent to receivers of the event notification 261</p>
<p>Step #2: Define the event member . 262</p>
<p>Step #3: Define a method responsible for raising the event to</p>
<p>notify registered objects that the event has occurred . 263</p>
<p>Step #4: Define a method that translates the input into the desired event 266</p>
<p>How the Compiler Implements an Event . 266</p>
<p>Designing a Type That Listens for an Event 269</p>
<p>Explicitly Implementing an Event 271</p>
<p><strong>12 </strong>Generics . 275</p>
<p>Generics in the Framework Class Library . 280</p>
<p>Wintellect’s Power Collections Library . 281</p>
<p>Generics Infrastructure . 282</p>
<p>Open and Closed Types 283</p>
<p>Generic Types and Inheritance 285</p>
<p>Generic Type Identity 287</p>
<p>Code Explosion . 288</p>
<p>Generic Interfaces 289</p>
<p>Generic Delegates 290</p>
<p>Delegate and Interface Contravariant and Covariant Generic Type Arguments 291</p>
<p>Generic Methods . 293</p>
<p>Generic Methods and Type Inference 294</p>
<p>Generics and Other Members . 296</p>
<p>Verifiability and Constraints . 296</p>
<p>Primary Constraints 299</p>
<p>Secondary Constraints . 300</p>
<p>Constructor Constraints 301</p>
<p>Other Verifiability Issues . 302</p>
<p><strong>13 </strong>Interfaces . 307</p>
<p>Class and Interface Inheritance . 308</p>
<p>Defining an Interface 308</p>
<p>Inheriting an Interface 310</p>
<p>More About Calling Interface Methods . 312</p>
<p>Implicit and Explicit Interface Method Implementations (What’s Happening</p>
<p>Behind the Scenes) . 314</p>
<p>Generic Interfaces 315</p>
<p>Generics and Interface Constraints 318</p>
<p>Implementing Multiple Interfaces That Have the Same Method Name</p>
<p>and Signature 319</p>
<p>Improving Compile-Time Type Safety with Explicit Interface Method</p>
<p>Implementations 320</p>
<p>Be Careful with Explicit Interface Method Implementations . 322</p>
<p>Design: Base Class or Interface? 325</p>
<p>Part III <strong>Essential Types</strong></p>
<p><strong>14 </strong>Chars, Strings, and Working with Text 327</p>
<p>Characters . 327</p>
<p>The System.String Type . 330</p>
<p>Constructing Strings 330</p>
<p>Strings Are Immutable . 333</p>
<p>Comparing Strings . 334</p>
<p>String Interning . 340</p>
<p>String Pooling . 343</p>
<p>Examining a String’s Characters and Text Elements . 343</p>
<p>Other String Operations 346</p>
<p>Constructing a String Efficiently 346</p>
<p>Constructing a StringBuilder Object 347</p>
<p>StringBuilder Members 348</p>
<p>Obtaining a String Representation of an Object: ToString 350</p>
<p>Specific Formats and Cultures 351</p>
<p>Formatting Multiple Objects into a Single String . 355</p>
<p>Providing Your Own Custom Formatter . 356</p>
<p>Parsing a String to Obtain an Object: Parse . 359</p>
<p>Encodings: Converting Between Characters and Bytes 361</p>
<p>Encoding and Decoding Streams of Characters and Bytes 367</p>
<p>Base-64 String Encoding and Decoding 368</p>
<p>Secure Strings . 369</p>
<p><strong>15 </strong>Enumerated Types and Bit Flags 373</p>
<p>Enumerated Types . 373</p>
<p>Bit Flags . 379</p>
<p>Adding Methods to Enumerated Types . 383</p>
<p><strong>16 </strong>Arrays 385</p>
<p>Initializing Array Elements 388</p>
<p>Casting Arrays 390</p>
<p>All Arrays Are Implicitly Derived from System.Array . 392</p>
<p>All Arrays Implicitly Implement IEnumerable, ICollection, and IList 393</p>
<p>Passing and Returning Arrays 394</p>
<p>Creating Non-Zero–Lower Bound Arrays 395</p>
<p>Array Access Performance 396</p>
<p>Unsafe Array Access and Fixed-Size Array 401</p>
<p><strong>17 </strong>Delegates . 405</p>
<p>A First Look at Delegates 405</p>
<p>Using Delegates to Call Back Static Methods . 408</p>
<p>Using Delegates to Call Back Instance Methods 409</p>
<p>Demystifying Delegates 410</p>
<p>Using Delegates to Call Back Many Methods (Chaining) . 415</p>
<p>C#’s Support for Delegate Chains . 419</p>
<p>Having More Control over Delegate Chain Invocation . 419</p>
<p>Enough with the Delegate Definitions Already (Generic Delegates) 422</p>
<p>C#’s Syntactical Sugar for Delegates 423</p>
<p>Syntactical Shortcut #1: No Need to Construct a Delegate Object 424</p>
<p>Syntactical Shortcut #2: No Need to Define a Callback Method 424</p>
<p>Syntactical Shortcut #3: No Need to Wrap Local Variables in a Class</p>
<p>Manually to Pass Them to a Callback Method 428</p>
<p>Delegates and Reflection . 431</p>
<p><strong>18 </strong>Custom Attributes 435</p>
<p>Using Custom Attributes 435</p>
<p>Defining Your Own Attribute Class . 439</p>
<p>Attribute Constructor and Field/Property Data Types 443</p>
<p>Detecting the Use of a Custom Attribute 444</p>
<p>Matching Two Attribute Instances Against Each Other 448</p>
<p>Detecting the Use of a Custom Attribute Without Creating Attribute-Derived</p>
<p>Objects . 451</p>
<p>Conditional Attribute Classes 454</p>
<p><strong>19 </strong>Nullable Value Types 457</p>
<p>C#’s Support for Nullable Value Types . 459</p>
<p>C#’s Null-Coalescing Operator 462</p>
<p>The CLR Has Special Support for Nullable Value Types 463</p>
<p>Boxing Nullable Value Types 463</p>
<p>Unboxing Nullable Value Types . 463</p>
<p>Calling GetType via a Nullable Value Type . 464</p>
<p>Calling Interface Methods via a Nullable Value Type 464</p>
<p>Part IV <strong>Core Facilities</strong></p>
<p><strong>20 </strong>Exceptions and State Management . 465</p>
<p>Defining “Exception” . 466</p>
<p>Exception-Handling Mechanics 467</p>
<p>The try Block . 468</p>
<p>The catch Block . 469</p>
<p>The finally Block 470</p>
<p>The System.Exception Class 474</p>
<p>FCL-Defined Exception Classes 478</p>
<p>Throwing an Exception . 480</p>
<p>Defining Your Own Exception Class . 481</p>
<p>Trading Reliability for Productivity . 484</p>
<p>Guidelines and Best Practices 492</p>
<p>Use finally Blocks Liberally 492</p>
<p>Don’t Catch Everything 494</p>
<p>Recovering Gracefully from an Exception 495</p>
<p>Backing Out of a Partially Completed Operation When an Unrecoverable</p>
<p>Exception Occurs—Maintaining State 496</p>
<p>Hiding an Implementation Detail to Maintain a “Contract” . 497</p>
<p>Unhandled Exceptions 500</p>
<p>Debugging Exceptions 504</p>
<p>Exception-Handling Performance Considerations 506</p>
<p>Constrained Execution Regions (CERs) . 509</p>
<p>Code Contracts . .512</p>
<p><strong>21 </strong>Automatic Memory Management (Garbage Collection) 519</p>
<p>Understanding the Basics of Working in a Garbage-Collected Platform 520</p>
<p>Allocating Resources from the Managed Heap 521</p>
<p>The Garbage Collection Algorithm 523</p>
<p>Garbage Collections and Debugging 527</p>
<p>Using Finalization to Release Native Resources . 530</p>
<p>Guaranteed Finalization Using CriticalFinalizerObject Types . 532</p>
<p>Interoperating with Unmanaged Code by Using SafeHandle Types 535</p>
<p>Using Finalization with Managed Resources 537</p>
<p>What Causes Finalize Methods to Be Called? 540</p>
<p>Finalization Internals . 541</p>
<p>The Dispose Pattern: Forcing an Object to Clean Up 544</p>
<p>Using a Type That Implements the Dispose Pattern . 548</p>
<p>C#’s using Statement . 551</p>
<p>An Interesting Dependency Issue . 554</p>
<p>Monitoring and Controlling the Lifetime of Objects Manually . 555</p>
<p>Resurrection 566</p>
<p>Generations . 568</p>
<p>Other Garbage Collection Features for Use with Native Resources . 574</p>
<p>Predicting the Success of an Operation that Requires a Lot of Memory 578</p>
<p>Programmatic Control of the Garbage Collector 580</p>
<p>Thread Hijacking 583</p>
<p>Garbage Collection Modes 585</p>
<p>Large Objects . 588</p>
<p>Monitoring Garbage Collections 589</p>
<p><strong>22 </strong>CLR Hosting and AppDomains . 591</p>
<p>CLR Hosting 592</p>
<p>AppDomains . 594</p>
<p>Accessing Objects Across AppDomain Boundaries 597</p>
<p>AppDomain Unloading . 609</p>
<p>AppDomain Monitoring . 610</p>
<p>AppDomain First-Chance Exception Notifications 612</p>
<p>How Hosts Use AppDomains . 612</p>
<p>Executable Applications 612</p>
<p>Microsoft Silverlight Rich Internet Applications . 613</p>
<p>Microsoft ASP.NET Web Forms and XML Web Services Applications 613</p>
<p>Microsoft SQL Server . 614</p>
<p>Your Own Imagination 614</p>
<p>Advanced Host Control 615</p>
<p>Managing the CLR by Using Managed Code 615</p>
<p>Writing a Robust Host Application . 616</p>
<p>How a Host Gets Its Thread Back 617</p>
<p><strong>23 </strong>Assembly Loading and Reflection 621</p>
<p>Assembly Loading 621</p>
<p>Using Reflection to Build a Dynamically Extensible Application . . . . . . . . . . . . . . . . . . .626</p>
<p>Reflection Performance 627</p>
<p>Discovering Types Defined in an Assembly . 628</p>
<p>What Exactly Is a Type Object? 628</p>
<p>Building a Hierarchy of Exception-Derived Types 631</p>
<p>Constructing an Instance of a Type 632</p>
<p>Designing an Application That Supports Add-Ins . 634</p>
<p>Using Reflection to Discover a Type’s Members 637</p>
<p>Discovering a Type’s Members 638</p>
<p>BindingFlags: Filtering the Kinds of Members That Are Returned . 643</p>
<p>Discovering a Type’s Interfaces 644</p>
<p>Invoking a Type’s Members 646</p>
<p>Bind Once, Invoke Multiple Times . 650</p>
<p>Using Binding Handles to Reduce Your Process’s Memory Consumption . 658</p>
<p><strong>24 </strong>Runtime Serialization . 661</p>
<p>Serialization/Deserialization Quick Start . 662</p>
<p>Making a Type Serializable 667</p>
<p>Controlling Serialization and Deserialization 668</p>
<p>How Formatters Serialize Type Instances 672</p>
<p>Controlling the Serialized/Deserialized Data 673</p>
<p>How to Define a Type That Implements ISerializable when the Base</p>
<p>Type Doesn’t Implement This Interface 678</p>
<p>Streaming Contexts . 680</p>
<p>Serializing a Type as a Different Type and Deserializing an Object as a</p>
<p>Different Object 682</p>
<p>Serialization Surrogates 684</p>
<p>Surrogate Selector Chains 688</p>
<p>Overriding the Assembly and/or Type When Deserializing an Object 689</p>
<p>Part V <strong>Threading</strong></p>
<p><strong>25 </strong>Thread Basics . 691</p>
<p>Why Does Windows Support Threads? 691</p>
<p>Thread Overhead . 692</p>
<p>Stop the Madness 696</p>
<p>CPU Trends 699</p>
<p>NUMA Architecture Machines . 700</p>
<p>CLR Threads and Windows Threads . 703</p>
<p>Using a Dedicated Thread to Perform an Asynchronous Compute-Bound</p>
<p>Operation . 704</p>
<p>Reasons to Use Threads 706</p>
<p>Thread Scheduling and Priorities 708</p>
<p>Foreground Threads versus Background Threads . 713</p>
<p>What Now? 715</p>
<p><strong>26 </strong>Compute-Bound Asynchronous Operations 717</p>
<p>Introducing the CLR’s Thread Pool . 718</p>
<p>Performing a Simple Compute-Bound Operation . 719</p>
<p>Execution Contexts 721</p>
<p>Cooperative Cancellation . 722</p>
<p>Tasks . 726</p>
<p>Waiting for a Task to Complete and Getting Its Result . 727</p>
<p>Cancelling a Task 729</p>
<p>Starting a New Task Automatically When Another Task Completes . 731</p>
<p>A Task May Start Child Tasks 733</p>
<p>Inside a Task 733</p>
<p>Task Factories 735</p>
<p>Task Schedulers . 737</p>
<p>Parallel’s Static For, ForEach, and Invoke Methods 739</p>
<p>Parallel Language Integrated Query 743</p>
<p>Performing a Periodic Compute-Bound Operation 747</p>
<p>So Many Timers, So Little Time 749</p>
<p>How the Thread Pool Manages Its Threads 750</p>
<p>Setting Thread Pool Limits 750</p>
<p>How Worker Threads Are Managed . 751</p>
<p>Cache Lines and False Sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .752</p>
<p><strong>27 </strong>I/O-Bound Asynchronous Operations . 755</p>
<p>How Windows Performs I/O Operations . 755</p>
<p>The CLR’s Asynchronous Programming Model (APM) 761</p>
<p>The AsyncEnumerator Class 765</p>
<p>The APM and Exceptions 769</p>
<p>Applications and Their Threading Models 770</p>
<p>Implementing a Server Asynchronously 773</p>
<p>The APM and Compute-Bound Operations 774</p>
<p>APM Considerations 776</p>
<p>Using the APM Without the Thread Pool 776</p>
<p>Always Call the EndXxx Method, and Call It Only Once . 777</p>
<p>Always Use the Same Object When Calling the EndXxx Method . 778</p>
<p>Using ref, out, and params Arguments with BeginXxx and</p>
<p>EndXxx Methods 778</p>
<p>You Can’t Cancel an Asynchronous I/O-Bound Operation 778</p>
<p>Memory Consumption 778</p>
<p>Some I/O Operations Must Be Done Synchronously . 779</p>
<p>FileStream-Specific Issues . 780</p>
<p>I/O Request Priorities 780</p>
<p>Converting the IAsyncResult APM to a Task 783</p>
<p>The Event-Based Asynchronous Pattern 784</p>
<p>Converting the EAP to a Task . 786</p>
<p>Comparing the APM and the EAP . 788</p>
<p>Programming Model Soup 788</p>
<p><strong>28 </strong>Primitive Thread Synchronization Constructs 791</p>
<p>Class Libraries and Thread Safety . 793</p>
<p>Primitive User-Mode and Kernel-Mode Constructs 794</p>
<p>User-Mode Constructs 796</p>
<p>Volatile Constructs . 797</p>
<p>Interlocked Constructs 803</p>
<p>Implementing a Simple Spin Lock . 807</p>
<p>The Interlocked Anything Pattern . 811</p>
<p>Kernel-Mode Constructs 813</p>
<p>Event Constructs . 817</p>
<p>Semaphore Constructs 819</p>
<p>Mutex Constructs . 820</p>
<p>Calling a Method When a Single Kernel Construct Becomes Available . 822</p>
<p><strong>29 </strong>Hybrid Thread Synchronization Constructs 825</p>
<p>A Simple Hybrid Lock 826</p>
<p>Spinning, Thread Ownership, and Recursion 827</p>
<p>A Potpourri of Hybrid Constructs . 829</p>
<p>The ManualResetEventSlim and SemaphoreSlim Classes 830</p>
<p>The Monitor Class and Sync Blocks . 830</p>
<p>The ReaderWriterLockSlim Class . 836</p>
<p>The OneManyLock Class 838</p>
<p>The CountdownEvent Class . 841</p>
<p>The Barrier Class . 841</p>
<p>Thread Synchronization Construct Summary 842</p>
<p>The Famous Double-Check Locking Technique . 844</p>
<p>The Condition Variable Pattern . 848</p>
<p>Using Collections to Avoid Holding a Lock for a Long Time . 851</p>
<p>The Concurrent Collection Classes . 856</p>
<p>Index . 861</p>
]]></content:encoded>
			<wfw:commentRss>http://bookcold.com/2010/02/279/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net中堆（Heap）和栈(Stack)的使用</title>
		<link>http://bookcold.com/2010/01/238</link>
		<comments>http://bookcold.com/2010/01/238#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:23:39 +0000</pubDate>
		<dc:creator>bookcold</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://bookcold.com/?p=238</guid>
		<description><![CDATA[<p>在C-SharpCorner上看到一个系列的文章，还不错！</p> <p>C# Heap(ing) Vs Stack(ing) in .NET: Part I 第一篇介绍基础知识，比如啥是值类型啥事引用类型</p> <p>C# Heap(ing) Vs Stack(ing) in .NET: Part II 第二篇介绍了点参数传递，函数调用中堆栈的使用</p> <p>C# Heap(ing) Vs Stack(ing) in .NET: Part III 第三篇介绍了类的拷贝</p> <p>C# Heap(ing) Vs Stack(ing) in .NET: Part IV 第四篇介绍了垃圾回收机制</p> <p>转一下，第三篇的内容，还是挺不错的</p> A Copy Is Not A Copy. <p>To clearly define the problem, let&#8217;s examine what happens when [...]]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://www.csharpcorner.com" target="_blank">C-SharpCorner</a>上看到一个系列的文章，还不错！</p>
<p><a href="C# Heap(ing) Vs Stack(ing) in .NET: Part I" target="_blank">C# Heap(ing) Vs Stack(ing) in .NET: Part I</a> 第一篇介绍基础知识，比如啥是值类型啥事引用类型</p>
<p><a href="http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory2B01142006125918PM/csharp_memory2B.aspx" target="_blank">C# Heap(ing) Vs Stack(ing) in .NET: Part II</a> 第二篇介绍了点参数传递，函数调用中堆栈的使用</p>
<p><a href="http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp_memory401152006094206AM/chsarp_memory4.aspx" target="_blank">C# Heap(ing) Vs Stack(ing) in .NET: Part III</a> 第三篇介绍了类的拷贝</p>
<p><a href="http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory_401282006141834PM/csharp_memory_4.aspx" target="_blank">C# Heap(ing) Vs Stack(ing) in .NET: Part IV</a> 第四篇介绍了垃圾回收机制<span id="more-238"></span></p>
<p>转一下，第三篇的内容，还是挺不错的</p>
<h2>A Copy Is Not A Copy.</h2>
<p>To clearly define the problem, let&#8217;s examine what happens when there is a value type on the heap versus having a reference type on the heap. First we&#8217;ll look at the value type. Take the following class and struct. We have a Dude class which contains a Name element and two Shoe(s). We have a CopyDude() method to make it easier to make new Dudes.</p>
<p>[code lang="csharp"]<br />
         public struct Shoe{<br />
               public string Color;<br />
           }</p>
<p>           public class Dude<br />
           {<br />
                public string Name;<br />
                public Shoe RightShoe;<br />
                public Shoe LeftShoe;</p>
<p>                public Dude CopyDude()<br />
                {<br />
                    Dude newPerson = new Dude();<br />
                     newPerson.Name = Name;<br />
                     newPerson.LeftShoe = LeftShoe;<br />
                     newPerson.RightShoe = RightShoe;</p>
<p>                     return newPerson;<br />
                }</p>
<p>                public override string ToString()<br />
                {<br />
                     return (Name + &quot; : Dude!, I have a &quot; + RightShoe.Color  +<br />
                         &quot; shoe on my right foot, and a &quot; +<br />
                          LeftShoe.Color + &quot; on my left foot.&quot;);<br />
                }</p>
<p>           }<br />
[/code]</p>
<p>Our Dude class is a variable type and because the Shoe struct is a member element of the class they both end up on the heap.</p>
<p><img src="http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp_memory401152006094206AM/Images/heapvsstack3-1.gif" alt="" /></p>
<p>When we run the following method:</p>
<p>[code lang="csharp"]<br />
           public static void Main()<br />
           {<br />
               Class1 pgm = new Class1();</p>
<p>                  Dude Bill = new Dude();<br />
                  Bill.Name = &quot;Bill&quot;;<br />
                  Bill.LeftShoe = new Shoe();<br />
                  Bill.RightShoe = new Shoe();<br />
                  Bill.LeftShoe.Color = Bill.RightShoe.Color = &quot;Blue&quot;;</p>
<p>                  Dude Ted =  Bill.CopyDude();<br />
                  Ted.Name = &quot;Ted&quot;;<br />
                  Ted.LeftShoe.Color = Ted.RightShoe.Color = &quot;Red&quot;;</p>
<p>                  Console.WriteLine(Bill.ToString());<br />
                  Console.WriteLine(Ted.ToString());<br />
           }<br />
[/code]</p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">We get the expected output:</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">Bill : Dude!, I have a Blue shoe on my right foot, and a Blue on my left foot.<br />
Ted : Dude!, I have a Red shoe on my right foot, and a Red on my left foot.</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">What happens if we make the Shoe a reference type?  Herein lies the problem. If we change the Shoe to a reference type as follows:</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;"> </span></p>
<p>[code lang="csharp"]&lt;/span&gt;</p>
<p>public class Shoe{</p>
<p>public string Color;</p>
<p>}</p>
<p>&lt;span style=&quot;font-family: Verdana, Arial, Helvetica, sans-serif;&quot;&gt;[/code]</p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">and run the exact same code in Main(), look how our input changes:</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">Bill : Dude!, I have a Red shoe on my right foot, and a Red on my left foot<br />
Ted : Dude!, I have a Red shoe on my right foot, and a Red on my left foot</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">The Red shoe is on the other foot. This is clearly an error. Do you see why it&#8217;s happening? Here&#8217;s what we end up with in the heap.</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;"><img src="http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp_memory401152006094206AM/Images/heapvsstack3-2.gif" border="0" alt="" hspace="0" align="baseline" /> </span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">Because we now are using Shoe as a reference type instead of a value type and when the contents of a reference type are copied only the pointer is copied (not the actual object being pointed to), we have to do some extra work to make our Shoe reference type behave more like a value type.</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">Luckily, we have an interface that will help us out: ICloneable. This interface is basically a contract that all Dudes will agree to and defines how a reference type is duplicated in order to avoid our &#8220;shoe sharing&#8221; error. All of our classes that need to be &#8220;cloned&#8221; should use the ICloneable interface, including the Shoe class.</span></p>
<p>ICloneable consists of one method: Clone()</p>
<p>[code lang="csharp"]<br />
                  public object Clone()<br />
                  {</p>
<p>                  }<br />
           public class Shoe : ICloneable<br />
             {<br />
                  public string Color;<br />
                  #region ICloneable Members</p>
<p>                  public object Clone()<br />
                  {<br />
                      Shoe newShoe = new Shoe();<br />
                      newShoe.Color = Color.Clone() as string;<br />
                      return newShoe;<br />
                  }</p>
<p>                  #endregion<br />
             }<br />
[/code]</p>
<p>Inside the Cone() method, we just make a new Shoe, clone all the reference types and copy all the value types and return the new object. You probably noticed that the string class already implements ICloneable so we can call Color.Clone(). Because Clone() returns a reference to an object, we have to &#8220;retype&#8221; the reference before we can set the Color of the shoe.</p>
<p>Next, in our CopyDude() method we need to clone the shoes instead of copying them</p>
<p>[code lang="csharp"]<br />
                public Dude CopyDude()<br />
                {<br />
                    Dude newPerson = new Dude();<br />
                     newPerson.Name = Name;<br />
                     newPerson.LeftShoe = LeftShoe.Clone() as Shoe;<br />
                     newPerson.RightShoe = RightShoe.Clone() as Shoe;</p>
<p>                     return newPerson;<br />
                }</p>
<p>           public static void Main()<br />
           {<br />
               Class1 pgm = new Class1();</p>
<p>                  Dude Bill = new Dude();<br />
                  Bill.Name = &quot;Bill&quot;;<br />
                  Bill.LeftShoe = new Shoe();<br />
                  Bill.RightShoe = new Shoe();<br />
                  Bill.LeftShoe.Color = Bill.RightShoe.Color = &quot;Blue&quot;;</p>
<p>                  Dude Ted =  Bill.CopyDude();<br />
                  Ted.Name = &quot;Ted&quot;;<br />
                  Ted.LeftShoe.Color = Ted.RightShoe.Color = &quot;Red&quot;;</p>
<p>                  Console.WriteLine(Bill.ToString());<br />
                  Console.WriteLine(Ted.ToString());</p>
<p>           }<br />
[/code]</p>
<p>We get:</p>
<p>Bill : Dude!, I have a Blue shoe on my right foot, and a Blue on my left foot<br />
Ted : Dude!, I have a Red shoe on my right foot, and a Red on my left foot</p>
<p>Which is what we want.</p>
<p>Wrapping Things Up.</p>
<p>So as a general practice, we want to always clone reference types and copy value types. (It will reduce the amount of aspirin you will have to purchase to manage the headaches you get debugging these kinds of errors.)</p>
<p>So in the spirit of headache reduction, let&#8217;s take it one step further and clean up the Dude class to implement ICloneable instead of using the CopyDude() method.</p>
<p>[code lang="csharp"]<br />
           public class Dude: ICloneable<br />
           {<br />
                public string Name;<br />
                public Shoe RightShoe;<br />
                public Shoe LeftShoe;</p>
<p>                public override string ToString()<br />
                {<br />
                     return (Name + &quot; : Dude!, I have a &quot; + RightShoe.Color  +<br />
                         &quot; shoe on my right foot, and a &quot; +<br />
                          LeftShoe.Color + &quot; on my left foot.&quot;);<br />
                    }<br />
                  #region ICloneable Members</p>
<p>                  public object Clone()<br />
                  {<br />
                       Dude newPerson = new Dude();<br />
                       newPerson.Name = Name.Clone() as string;<br />
                       newPerson.LeftShoe = LeftShoe.Clone() as Shoe;<br />
                       newPerson.RightShoe = RightShoe.Clone() as Shoe;</p>
<p>                       return newPerson;<br />
                  }</p>
<p>                  #endregion<br />
             }</p>
<p>           public static void Main()<br />
           {<br />
               Class1 pgm = new Class1();</p>
<p>                  Dude Bill = new Dude();<br />
                  Bill.Name = &quot;Bill&quot;;<br />
                  Bill.LeftShoe = new Shoe();<br />
                  Bill.RightShoe = new Shoe();<br />
                  Bill.LeftShoe.Color = Bill.RightShoe.Color = &quot;Blue&quot;;</p>
<p>                  Dude Ted =  Bill.Clone() as Dude;<br />
                  Ted.Name = &quot;Ted&quot;;<br />
                  Ted.LeftShoe.Color = Ted.RightShoe.Color = &quot;Red&quot;;</p>
<p>                  Console.WriteLine(Bill.ToString());<br />
                  Console.WriteLine(Ted.ToString());</p>
<p>           }<br />
[/code]<br />
And our final output is:  Bill : Dude!, I have a Blue shoe on my right foot, and a Blue on my left foot. Ted : Dude!, I have a Red shoe on my right foot, and a Red on my left foot.  So all is well.  Something interesting to note is that the assignment operator (the &#8220;=&#8221; sign) for the System.String class actually clones the string so you don&#8217;t have to worry about duplicate references. However you do have to watch our for memory bloating. If you look back at the diagrams, because the string is a reference type it really should be a pointer to another object in the heap, but for simplicity&#8217;s sake, it&#8217;s shown as a value type.  In Conclusion.  As a general practice, if we plan on ever copying of our objects, we should implement (and use) ICloneable.  This enables our reference types to somewhat mimic the behavior of a value type. As you can see, it is very important to keep track of what type of variable we are dealing with because of differences in how the memory is allocated for value types and reference types.</pre>
]]></content:encoded>
			<wfw:commentRss>http://bookcold.com/2010/01/238/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lambda表达式对List的处理</title>
		<link>http://bookcold.com/2010/01/231</link>
		<comments>http://bookcold.com/2010/01/231#comments</comments>
		<pubDate>Wed, 20 Jan 2010 16:11:28 +0000</pubDate>
		<dc:creator>bookcold</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lambda Expressions]]></category>

		<guid isPermaLink="false">http://bookcold.com/2010/01/21/231/</guid>
		<description><![CDATA[<p>&#160;</p> <p> <p>Lambda表达式使得List的过滤和排序更加简洁！</p> <p>定义一个Employee类：</p> 1: public class Employee 2: { 3: public string FirstName {set; get;} 4: public string LastName {set; get;} 5: public decimal Salary {set; get;} 6: public bool IsManager {set; get;} 7: } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p> <span id="more-231"></span>
<p>Lambda表达式使得List的过滤和排序更加简洁！</p>
<p>定义一个Employee类：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">public</span> <span class="kwrd">class</span> Employee</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> FirstName {set; get;}</pre>
<pre><span class="lnum">   4:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> LastName {set; get;}</pre>
<pre class="alt"><span class="lnum">   5:  </span>    <span class="kwrd">public</span> <span class="kwrd">decimal</span> Salary {set; get;}</pre>
<pre><span class="lnum">   6:  </span>    <span class="kwrd">public</span> <span class="kwrd">bool</span> IsManager {set; get;}</pre>
<pre class="alt"><span class="lnum">   7:  </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>再定义一个Employee的列表：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>List&lt;Employee&gt; employees = <span class="kwrd">new</span> List&lt;Employee&gt;( );</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>1. FindAll()操作</h3>
<p>原始的方法：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">foreach</span> (Employee employee <span class="kwrd">in</span> employees)</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>    <span class="kwrd">if</span> (employee.IsManager == <span class="kwrd">true</span>)</pre>
<pre><span class="lnum">   4:  </span>        managers.Add(employee);</pre>
<pre class="alt"><span class="lnum">   5:  </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>Lambda表达式：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>List&lt;Employee&gt; managers = employees.FindAll(employee =&gt; employee.IsManager == <span class="kwrd">true</span>);</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>2. Where()操作</h3>
<p>where()和FindAll()类似，有时候用where能使代码更好理解：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">foreach</span> (Employee employee <span class="kwrd">in</span> employees.Where(e =&gt; e.IsManager == <span class="kwrd">true</span>))</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>    <span class="rem">// do something</span></pre>
<pre><span class="lnum">   4:  </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<h3>3. Find()操作</h3>
<p>Find()返回列表的第一个对象：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>Employee firstManager = employees.Find(employee =&gt; employee.IsManager == <span class="kwrd">true</span>);</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">if</span> (firstManager == <span class="kwrd">null</span>)</pre>
<pre class="alt"><span class="lnum">   3:  </span>    Console.WriteLine(<span class="str">&quot;No managers found in list.&quot;</span>);</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<h3>4. ForEach( )操作</h3>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span> employees.ForEach(e =&gt; e.Salary += 100);</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<h3>5. OrderBy( )&#160; and&#160; OrderByDescending( )操作</h3>
<p>OrderBy()返回一个升序排列的List；OrderByDescending()返回一个降序排列的List：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>List&lt;Employee&gt; sortedList = employees.OrderBy(e =&gt; e.Age).ToList();</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<div class="csharpcode">
<pre class="alt">

<span class="lnum"></span>&#160;

<span class="lnum">   1:  </span> List&lt;Employee&gt; sortedList = employees.OrderByDescending(e =&gt; e.Age).ToList();
</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>6. Sort( )</h3>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>employees.Sort((e1, e2) =&gt; e1.DOB.CompareTo(e2.DOB));</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<h3>7. Getting Fancy</h3>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">public</span> <span class="kwrd">enum</span> SortOrder { Ascending, Decending };</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Sort&lt;TKey&gt;(<span class="kwrd">ref</span> List&lt;Employee&gt; list, Func&lt;Employee, TKey&gt; sortKey, </pre>
<pre class="alt"><span class="lnum">   3:  </span>    SortOrder sortOrder)</pre>
<pre><span class="lnum">   4:  </span>{</pre>
<pre class="alt"><span class="lnum">   5:  </span>    <span class="kwrd">if</span> (sortOrder == SortOrder.Ascending)</pre>
<pre><span class="lnum">   6:  </span>        list = list.OrderBy(sortKey).ToList();</pre>
<pre class="alt"><span class="lnum">   7:  </span>    <span class="kwrd">else</span></pre>
<pre><span class="lnum">   8:  </span>        list = list.OrderByDescending(sortKey).ToList();</pre>
<pre class="alt"><span class="lnum">   9:  </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>现在可以这样使用：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>Employee.Sort(employees, e =&gt; e.Salary, SortOrder.Ascending);</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>文章来源于：</p>
<p><a href="http://www.c-sharpcorner.com/UploadFile/afenster/LambdaExpressionsAreWonderful12022009002148AM/LambdaExpressionsAreWonderful.aspx">http://www.c-sharpcorner.com/UploadFile/afenster/LambdaExpressionsAreWonderful12022009002148AM/LambdaExpressionsAreWonderful.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bookcold.com/2010/01/231/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net 开发习惯【转】</title>
		<link>http://bookcold.com/2010/01/230</link>
		<comments>http://bookcold.com/2010/01/230#comments</comments>
		<pubDate>Tue, 19 Jan 2010 15:39:44 +0000</pubDate>
		<dc:creator>bookcold</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://bookcold.com/2010/01/19/230/</guid>
		<description><![CDATA[<p>1、不要硬编string/ numeric，可以使用一些常量代替。 （提高可读性）</p> 1: int Count; 2: Count = 100; 3: private static const int ZERO = 0; 4: if( Count == ZERO ) 5: { 6: // 执行一些操作 7: } <p></p> <p>2、对于字符串比较-使用String. Empty ，而不是&#8221;"。</p> <p></p> <p>3、不要声明成员变量为 public 或者proteted，尽量使用private 成员变量和public/protected 属性。 （修改）</p> <p>4、当我们要在循环操作字符串，使用StringBuilder，而不是字符串，示例如下。</p> <p>不好的习惯：</p> 1: String temp = String.Empty; 2: for( int i = [...]]]></description>
			<content:encoded><![CDATA[<p>1、不要硬编string/ numeric，可以使用一些常量代替。 （提高可读性）</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">int</span> Count;</pre>
<pre><span class="lnum">   2:  </span>Count = 100;</pre>
<pre class="alt"><span class="lnum">   3:  </span><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">const</span> <span class="kwrd">int</span> ZERO  =  0;</pre>
<pre><span class="lnum">   4:  </span><span class="kwrd">if</span>(  Count  ==  ZERO )</pre>
<pre class="alt"><span class="lnum">   5:  </span>{</pre>
<pre><span class="lnum">   6:  </span><span class="rem">// 执行一些操作</span></pre>
<pre class="alt"><span class="lnum">   7:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>2、对于字符串比较-使用String. Empty ，而不是&#8221;"。</p>
<p><span id="more-230"></span></p>
<p>3、不要声明成员变量为 public 或者proteted，尽量使用private 成员变量和public/protected 属性。 （修改）</p>
<p>4、当我们要在循环操作字符串，使用StringBuilder，而不是字符串，示例如下。</p>
<p>不好的习惯：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>String  temp = String.Empty;</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">for</span>( <span class="kwrd">int</span> i = 0 ; i&lt;= 100; i++)</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>      temp += i.ToString();</pre>
<pre class="alt"><span class="lnum">   5:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>好点的习惯：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>StringBuilder sb = <span class="kwrd">new</span> StringBuilder();</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">for</span> ( <span class="kwrd">int</span> i = 0 ; i&lt;= 100; i++)</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>      sb.Append(i.ToString());</pre>
<pre class="alt"><span class="lnum">   5:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>5、简单的操作，比起Collection更倾向使用Array。 （视情况，这里是建议）</p>
<p>6、比起ArrayList更倾向使用Generic Collection。 （视情况，这里是建议）</p>
<p>7、比起HashTable更倾向使用Generic Dictionary。 （视情况，这里是建议）</p>
<p>8、对于字符串的操作和存储，倾向于StringCollection和StringDictionary。 （视情况，这里是建议）</p>
<p>9、使用适合的数据类型。</p>
<p>例如：你想要判断状态，使用bool比int要好。</p>
<p>不好的习惯：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">int</span> Check = 0;</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">if</span>( Check == 0 )</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>        <span class="rem">// 执行一些操作</span></pre>
<pre class="alt"><span class="lnum">   5:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>好点的习惯：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">bool</span> Check = <span class="kwrd">false</span>;</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">if</span>(!Check)</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>         <span class="rem">// 执行一些操作</span></pre>
<pre class="alt"><span class="lnum">   5:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>10、使用as做类型转换的时候，对转换后的值进行null值判断</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">class</span> A</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span></pre>
<pre><span class="lnum">   4:  </span>}</pre>
<pre class="alt"><span class="lnum">   5:  </span><span class="kwrd">class</span> B : A</pre>
<pre><span class="lnum">   6:  </span>{</pre>
<pre class="alt"><span class="lnum">   7:  </span></pre>
<pre><span class="lnum">   8:  </span>}</pre>
<pre class="alt"><span class="lnum">   9:  </span>B objB = <span class="kwrd">new</span> B();</pre>
<pre><span class="lnum">  10:  </span>A objA1  = (A) objB;</pre>
<pre class="alt"><span class="lnum">  11:  </span>A objA2 = objB <span class="kwrd">as</span> A;</pre>
<pre><span class="lnum">  12:  </span><span class="kwrd">if</span>( objA2 != <span class="kwrd">null</span>)</pre>
<pre class="alt"><span class="lnum">  13:  </span>{</pre>
<pre><span class="lnum">  14:  </span>     <span class="rem">//执行所需的操作</span></pre>
<pre class="alt"><span class="lnum">  15:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>11、创建wcf代理，可以使用using表达式。 （很多地方可以这样使用）</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">using</span>(Cerate the proxy)</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>         <span class="rem">//执行所需的操作</span></pre>
<pre><span class="lnum">   4:  </span>}</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>12、对于昂贵的资源(例如Connection, File 等等)，遵照&#8217;Acquire late, release early’ (尽量晚的获取，尽量早的释放)准则。</p>
<p>例子：如果你想在数据操作时，使用的SqlConnection对象，请在方法级别，而不是在类级别创建实例。</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>        <span class="kwrd">class</span> MyData</pre>
<pre><span class="lnum">   2:  </span>        {</pre>
<pre class="alt"><span class="lnum">   3:  </span>             <span class="kwrd">public</span> MyData()</pre>
<pre><span class="lnum">   4:  </span>            {</pre>
<pre class="alt"><span class="lnum">   5:  </span>            }</pre>
<pre><span class="lnum">   6:  </span>            <span class="kwrd">public</span> List&lt;Customer&gt; GetAllCustomer()</pre>
<pre class="alt"><span class="lnum">   7:  </span>            {</pre>
<pre><span class="lnum">   8:  </span>               <span class="kwrd">using</span> (SqlConnection objConnection = <span class="kwrd">new</span> SqlConnection(<span class="str">"Connection string"</span>))</pre>
<pre class="alt"><span class="lnum">   9:  </span>               {</pre>
<pre><span class="lnum">  10:  </span>                   <span class="rem">//执行一些操作得到需要的数据</span></pre>
<pre class="alt"><span class="lnum">  11:  </span>                }</pre>
<pre><span class="lnum">  12:  </span></pre>
<pre class="alt"><span class="lnum">  13:  </span>            }</pre>
<pre><span class="lnum">  14:  </span>        }</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>如果你想创建的类级别SqlConnection实例，确保您的类实现了IDisposable接口，并在Dispose()中清理SqlConnection实例。</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>        <span class="kwrd">class</span> MyData : IDisposable</pre>
<pre><span class="lnum">   2:  </span>        {</pre>
<pre class="alt"><span class="lnum">   3:  </span>            SqlConnection objConnection ;</pre>
<pre><span class="lnum">   4:  </span>            <span class="kwrd">public</span> MyData()</pre>
<pre class="alt"><span class="lnum">   5:  </span>            {</pre>
<pre><span class="lnum">   6:  </span>                objConnection = <span class="kwrd">new</span> SqlConnection(<span class="str">"Connection string"</span>);</pre>
<pre class="alt"><span class="lnum">   7:  </span>            }</pre>
<pre><span class="lnum">   8:  </span>            <span class="kwrd">public</span> List&lt;Customer&gt; GetAllCustomer()</pre>
<pre class="alt"><span class="lnum">   9:  </span>            {</pre>
<pre><span class="lnum">  10:  </span>                <span class="rem">//通过objConnection得到需要的数据</span></pre>
<pre class="alt"><span class="lnum">  11:  </span>            }</pre>
<pre><span class="lnum">  12:  </span>            <span class="kwrd">public</span> <span class="kwrd">void</span> Dispose()</pre>
<pre class="alt"><span class="lnum">  13:  </span>            {</pre>
<pre><span class="lnum">  14:  </span>                <span class="rem">//清理SqlConnection实例</span></pre>
<pre class="alt"><span class="lnum">  15:  </span>                <span class="kwrd">if</span>( objConnection != <span class="kwrd">null</span> )</pre>
<pre><span class="lnum">  16:  </span>                {</pre>
<pre class="alt"><span class="lnum">  17:  </span>                    <span class="kwrd">if</span>( objConnection.State == ConnectionState.Open)</pre>
<pre><span class="lnum">  18:  </span>                    {</pre>
<pre class="alt"><span class="lnum">  19:  </span>                       objConnection.Close();</pre>
<pre><span class="lnum">  20:  </span>                    }</pre>
<pre class="alt"><span class="lnum">  21:  </span>                }</pre>
<pre><span class="lnum">  22:  </span>            }</pre>
<pre class="alt"><span class="lnum">  23:  </span>        }</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>13、如果你不想别人扩展你的类功能，使用‘sealed’。</p>
<p>14、避免为每个类都声明‘destructor’ ，因为它会增加不需要常驻内存的类的生命周期。</p>
<p>15、相对manual threading，更倾向用Thread Pool 。</p>
<p>16、在循环内不要去调用其它方法。 （call function 有性能损耗）</p>
<p>例如：</p>
<p>不好的习惯：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">for</span>( <span class="kwrd">int</span> i = 0; i&lt;= 100; i++)</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>    Calculate(i);</pre>
<pre><span class="lnum">   4:  </span>}</pre>
<pre> 好点的习惯：</pre>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">for</span>( <span class="kwrd">int</span> i = 0; i&lt;= 100; i++)</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>       <span class="rem">//直接写Calculate逻辑。</span></pre>
<pre><span class="lnum">   4:  </span>}</pre>
<p>17、不要在循环内处理异常，而是将循环处理的逻辑放在try/catch里面</p>
<p>不好的习惯：</p>
</div>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">for</span>(<span class="kwrd">int</span> i = 0 ; i&lt;= 100; i++)</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre class="alt"><span class="lnum">   3:  </span>   <span class="kwrd">try</span></pre>
<pre><span class="lnum">   4:  </span>   {</pre>
<pre class="alt"><span class="lnum">   5:  </span>   }</pre>
<pre><span class="lnum">   6:  </span>   <span class="kwrd">catch</span>(Exception ex)</pre>
<pre class="alt"><span class="lnum">   7:  </span>   {</pre>
<pre><span class="lnum">   8:  </span>    <span class="kwrd">throw</span> ex;</pre>
<pre class="alt"><span class="lnum">   9:  </span>   }</pre>
<pre><span class="lnum">  10:  </span>}</pre>
<pre>好点的习惯：</pre>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>   <span class="kwrd">try</span></pre>
<pre><span class="lnum">   2:  </span>   {</pre>
<pre class="alt"><span class="lnum">   3:  </span>     <span class="kwrd">for</span>(<span class="kwrd">int</span> i = 0 ; i&lt;= 100; i++)</pre>
<pre><span class="lnum">   4:  </span>     {</pre>
<pre class="alt"><span class="lnum">   5:  </span>     }</pre>
<pre><span class="lnum">   6:  </span>   }</pre>
<pre class="alt"><span class="lnum">   7:  </span>   <span class="kwrd">catch</span>(Exception ex)</pre>
<pre><span class="lnum">   8:  </span>   {</pre>
<pre class="alt"><span class="lnum">   9:  </span>       <span class="kwrd">throw</span> ex;</pre>
<pre><span class="lnum">  10:  </span>   }</pre>
<p>18、不用通过异常处理应用程序的逻辑</p>
<p>例如：</p>
<p>不好的习惯：</p>
</div>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>  <span class="kwrd">try</span></pre>
<pre><span class="lnum">   2:  </span>  {</pre>
<pre class="alt"><span class="lnum">   3:  </span>    <span class="kwrd">int</span> x,y,z;</pre>
<pre><span class="lnum">   4:  </span>    x = 0;</pre>
<pre class="alt"><span class="lnum">   5:  </span>    y = 10;</pre>
<pre><span class="lnum">   6:  </span>    z = y/x;</pre>
<pre class="alt"><span class="lnum">   7:  </span>   }</pre>
<pre><span class="lnum">   8:  </span>   <span class="kwrd">catch</span>(DevideByZeroException ex)</pre>
<pre class="alt"><span class="lnum">   9:  </span>   {</pre>
<pre><span class="lnum">  10:  </span>    Throw ex;</pre>
<pre class="alt"><span class="lnum">  11:  </span>   }</pre>
<p>好点的习惯：</p>
</div>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">try</span></pre>
<pre><span class="lnum">   2:  </span> {</pre>
<pre class="alt"><span class="lnum">   3:  </span>   <span class="kwrd">int</span> x,y,z;</pre>
<pre><span class="lnum">   4:  </span>   x = 0;</pre>
<pre class="alt"><span class="lnum">   5:  </span>   y = 10;</pre>
<pre><span class="lnum">   6:  </span>   <span class="kwrd">if</span>( x != 0 )</pre>
<pre class="alt"><span class="lnum">   7:  </span>   {</pre>
<pre><span class="lnum">   8:  </span>      z = y/x;</pre>
<pre class="alt"><span class="lnum">   9:  </span>   }</pre>
<pre><span class="lnum">  10:  </span> }</pre>
<pre class="alt"><span class="lnum">  11:  </span> <span class="kwrd">catch</span>(Exception ex)</pre>
<pre><span class="lnum">  12:  </span> {</pre>
<pre class="alt"><span class="lnum">  13:  </span> }</pre>
</div>
<p>19、相对for/while  ，倾向使用foreach循环。</p>
<p>20、使用多层架构的系统，层与层之间的交互，比起DataSet/DataTables更倾向于使用对象传递数据。</p>
<h2>40条ASP.NET开发Tip</h2>
<p>1、在compilation 下，请设置debug=false ，如下：</p>
<p>default Language=&#8221;c#&#8221; debug=&#8221;false&#8221;</p>
<p>2、请使用Server.Transfer代替Response.Redirect。</p>
<p>3、使用Validator控件，请要经常检查Page.IsValid。</p>
<p>4、请使用foreach循环，而不是为字符串迭代循环。</p>
<p>5、请使用客户端验证方式(不要每次都在服务端验证)。</p>
<p>6、为了避免重复代码执行，请检查“Page.IsPostBack”。</p>
<p>7、GIF 和PNG类似，但是PNG通常产生一个较小体积的文件。（当然，有些浏览器不支持PNG格式）</p>
<p>8、更新二进制文件时，请使用AppOffline.htm 。</p>
<p>9、除非需要，否则请关闭跟踪。</p>
<p>&lt;trace enabled=&#8221;false&#8221; requestLimit=&#8221;10&#8243; pageOutput=&#8221;false&#8221; traceMode=&#8221;SortByTime&#8221; localOnly=&#8221;true&#8221;/&gt;</p>
<p>10、编译页面，请禁用AutoEventWireup。在Machine.config文件中请设置AutoEventWireup为false。</p>
<p>11、如果不需要，请关闭Session会话。</p>
<p>&lt;sessionstate timeout=&#8221;20&#8243; cookieless=&#8221;false&#8221; mode=&#8221;Off&#8221; stateconnectionstring=&#8221;tcpip=127.0.0.1:42424&#8243; sqlconnectionstring=&#8221;data source=127.0.0.1;Trusted_Connection=no&#8221;&gt;</p>
<p>12、在你生成最终版本的应用程序之前，请选择Release模式。默认是Debug。</p>
<p>13、如果不需要请禁用ViewState 。</p>
<p>EnableViewState=&#8221;false&#8221;</p>
<p>14、请避免频繁的访问数据库。</p>
<p>15、使用缓存提高你的应用程序的性能。</p>
<p>16、验证所有的用户输入。</p>
<p>17、请最后释放所有资源。</p>
<p>18、String 和Stringbuilder。</p>
<p>修改字符串时，使用Stringbuilder而不是String ，在每次字符串修改的时候，String都会占据不同的内存空间，而Stringbuilder只使用同一个内存空间</p>
<p>19、切勿直接使用对象的值，先从本地变量获取对象的值，然后再使用。因为直接读取对象的值比读取变量更花时间。</p>
<p>20、避免异常：使用if。</p>
<p>21、代码优化：避免使用：x = x +1，而是使用x+=1比较好。</p>
<p>22、数据访问技术：DataReaders提供快速有效的数据检索方法。在性能方面，DataReader是速度远远超过DataSets 。</p>
<p>23、在做一个笨重的ASP代码的处理之前，你进行检查以确保Response.IsClientConnected。</p>
<p>24、避免session变量，因为每个ASP页面是在不同的线程运行和session调用将会被逐一序列化。这样会降低应用程序。你可以使用QueryString集合或者表单上面的hidden变量来保存值。</p>
<p>25、使buffer有效，能提高性能，如：</p>
<p>&lt;% response.buffer=true %&gt;</p>
<p>接着使用：</p>
<p>&lt;% response.flush=true %&gt;</p>
<p>26、使用Repeater控件代替DataGrid，DataList，因为它是高效的，可定制的，和可编程的。</p>
<p>27、在数据库中检索大量数据，数据列表消耗更多的时间。</p>
<p>分页将显示特定的数据，但是要考虑所有数据负载。只取当前页需要的数据。</p>
<p>28、避免内嵌JavaScript和CSS。</p>
<p>29、使用单个的css文件，而不是多个css文件。</p>
<p>请尽量将您所有的css合并成一个css的类文件，不管文件大小，大量的.css文件会造成大量的请求。.css文件通常是由浏览器缓存，这样一个单一的沉重的.css文件不会导致在每个页面请求时会有漫长的等待。</p>
<p>内嵌.CSS类导致HTML沉重，因此我觉得：首先考虑一个single.css文件。</p>
<p>30、减少cookie的大小。</p>
<p>31、压缩CSS, JavaScript 和Images。</p>
<p>可以使用在线的压缩，压缩文件，将下列网页和优化的代码替换为您的文件内容。</p>
<p><a href="http://iceyboard.no-ip.org/projects/css_compressor">http://iceyboard.no-ip.org/projects/css_compressor</a>[<a href="http://iceyboard.no-ip.org/projects/css_compressor">^</a>]  CSS 压缩</p>
<p><a href="http://www.xtreeme.com/javascript-optimizer/">www.xtreeme.com/javascript-optimizer/</a>[<a href="http://www.xtreeme.com/javascript-optimizer/">^</a>] .  JS 压缩</p>
<p>32、适当地使用缓存。</p>
<p>i、页面输出缓存：</p>
<p>&lt;%@ OutputCache Duration=&#8221;3600&#8243; VaryByParam=&#8221;none&#8221; %&gt;</p>
<p>ii、页片段缓存：</p>
<p>在每个用户控件中写页面输出缓存</p>
<p>iii、数据缓存：</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>&lt;script language=<span class="str">"C#"</span> runat=<span class="str">"server"</span>&gt;</pre>
<pre><span class="lnum">   2:  </span> Protected <span class="kwrd">void</span> Page_Load (Object src, EventArgs e)</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span> DataView dv = (DataView) Cache. Get (<span class="str">"EmployeesDataView"</span>);</pre>
<pre class="alt"><span class="lnum">   5:  </span> If (dv == <span class="kwrd">null</span>)</pre>
<pre><span class="lnum">   6:  </span> { <span class="rem">// wasn't there</span></pre>
<pre class="alt"><span class="lnum">   7:  </span>  SqlConnection conn = <span class="kwrd">new</span> SqlConnection (<span class="str">"server=localhost;uid=sa;pwd=;database=Test"</span>);</pre>
<pre><span class="lnum">   8:  </span>  SqlDataAdapter da =<span class="kwrd">new</span> SqlDataAdapter (<span class="str">"select * from Employees"</span>, conn);</pre>
<pre class="alt"><span class="lnum">   9:  </span>  Dataset ds = <span class="kwrd">new</span> DataSet();</pre>
<pre><span class="lnum">  10:  </span>  da.Fill(ds, <span class="str">"Employees"</span>);</pre>
<pre class="alt"><span class="lnum">  11:  </span>  dv = ds.Tables[<span class="str">"Employees"</span>].DefaultView;</pre>
<pre><span class="lnum">  12:  </span>  Cache.Insert (<span class="str">"EmployeesDataView"</span>, dv);</pre>
<pre class="alt"><span class="lnum">  13:  </span>  conn.Close();</pre>
<pre><span class="lnum">  14:  </span>}</pre>
<pre class="alt"><span class="lnum">  15:  </span> Else</pre>
<pre><span class="lnum">  16:  </span> Response.Write (<span class="str">"&lt;h2&gt;Loaded employees from data cache! &lt;/h2&gt;"</span>);</pre>
<pre class="alt"><span class="lnum">  17:  </span> lb1.DataSource = dv;</pre>
<pre><span class="lnum">  18:  </span> lb1.DataTextField = <span class="str">"Name"</span>;</pre>
<pre class="alt"><span class="lnum">  19:  </span> lb1.DataValueField = <span class="str">"Age"</span>;</pre>
<pre><span class="lnum">  20:  </span> DataBind () ;</pre>
<pre class="alt"><span class="lnum">  21:  </span>}</pre>
<pre><span class="lnum">  22:  </span>&lt;/script&gt;</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->33、服务器端使用诸如Port80s压缩软件<a href="http://www.port80software.com/products/httpzip/">http://www.port80software.com/products/httpzip/</a>[<a href="http://www.port80software.com/products/httpzip/">^</a>]。</p>
<p>34、使用了“using”。</p>
<p>35、不要声明成员变量为 public 或者proteted，尽量使用private 成员变量和public/protected 属性。</p>
<p>36、使用strString=string.Empty 代替 strString=&#8221;" 。</p>
<p>37、请尽可能减轻你的页面文件，尽量避免不必要的标签，例如使用div代替table。</p>
<p>38、在div中写静态的消息，必要的时候才显示出来。这比你设置服务端的label和div的text属性快。</p>
<p>39、如果可能的话，一次性检索数据库中的数据。尽可能不要添加数据库的访问。因此，整合来自不同表datafields和选择它们。</p>
<p>40、给WebControl取个简短的名字。</p>
<h5>转载自：<a href="http://zhuqil.cnblogs.com">http://zhuqil.cnblogs.com</a></h5>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --> <!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --> <!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --> <!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></div>
]]></content:encoded>
			<wfw:commentRss>http://bookcold.com/2010/01/230/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net下基于AOP的角色权限控制</title>
		<link>http://bookcold.com/2010/01/228</link>
		<comments>http://bookcold.com/2010/01/228#comments</comments>
		<pubDate>Sat, 16 Jan 2010 08:52:17 +0000</pubDate>
		<dc:creator>bookcold</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[AOP]]></category>
		<category><![CDATA[RBAC]]></category>

		<guid isPermaLink="false">http://bookcold.com/2010/01/16/228/</guid>
		<description><![CDATA[<p>几篇相当不错的文章：</p> <p>1. AOP技术基础</p> <p>2. 在.Net中关于AOP的实现</p> <p>3. 在.Net中关于AOP的实现（补遗）</p> <p>ps：张逸真是神啊！</p> <p>4.  Aspect Oriented Programming using .NET</p> <p>5. 利用 AOP 实现 .NET 上完整的基于角色的访问控制（RBAC）模型</p> ]]></description>
			<content:encoded><![CDATA[<p>几篇相当不错的文章：</p>
<p>1. <a href="http://www.cnblogs.com/wayfarer/articles/241024.html">AOP技术基础</a></p>
<p>2. <a href="http://www.cnblogs.com/wayfarer/articles/227663.html">在.Net中关于AOP的实现</a></p>
<p>3. <a href="http://www.cnblogs.com/wayfarer/articles/233212.html">在.Net中关于AOP的实现（补遗）</a></p>
<p>ps：张逸真是神啊！</p>
<p>4.  <a href="http://www.developerfusion.com/article/5307/aspect-oriented-programming-using-net/3/">Aspect Oriented Programming using .NET</a></p>
<p>5. <a href="http://www.joycode.com/moslem/archive/2006/10/16/85194.joy">利用 AOP 实现 .NET 上完整的基于角色的访问控制（RBAC）模型</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bookcold.com/2010/01/228/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>12+ open source projects for .NET you probably didn&#8217;t know about.(12个.NET的开源项目)</title>
		<link>http://bookcold.com/2010/01/212</link>
		<comments>http://bookcold.com/2010/01/212#comments</comments>
		<pubDate>Fri, 08 Jan 2010 07:14:24 +0000</pubDate>
		<dc:creator>bookcold</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[OpenSource]]></category>

		<guid isPermaLink="false">http://bookcold.com/2010/01/08/212/</guid>
		<description><![CDATA[ <p></p> Umbraco <p></p> <p>URL: http://www.umbraco.org</p> <p>Source Code: Grab the source code here.</p> <p>I’ve mentioned umbraco as an open source system to keep an eye on before, in our compilation of open source CMS systems.</p> <p>It impresses me on each release, and has just put together an awesome sample site that is well worth [...]]]></description>
			<content:encoded><![CDATA[<h4></h4>
<p><span id="more-212"></span></p>
<h4>Umbraco</h4>
<p><a href="http://www.umbraco.org"><img title="umbraco" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/umbraco.jpg" alt="umbraco" width="222" height="166" /></a></p>
<p><strong>URL:</strong> <a href="http://www.umbraco.org">http://www.umbraco.org</a></p>
<p><strong>Source Code:</strong> <a href="http://www.codeplex.com/umbraco/sourcecontrol/listdownloadablecommits.aspx">Grab the source code here.</a></p>
<p>I’ve mentioned umbraco as an open source system to keep an eye on before, in our compilation of open source CMS systems.</p>
<p>It impresses me on each release, and has just put together an awesome sample site that is well worth a look, and will enable developers to get up to speed quickly and easily.</p>
<h4>i386 Newsletter System</h4>
<p><strong>URL:</strong> <a href="http://www.i386.com/Products/Newsletter.aspx">http://www.i386.com/Products/Newsletter.aspx</a></p>
<p><a href="http://www.i386.com/Products/Newsletter.aspx"><img title="i386" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/i386.jpg" alt="i386" width="214" height="160" /></a></p>
<p><strong>Source Code:</strong> <a href="http://www.codeplex.com/newsletter">Grab the source code here</a></p>
<p>I came across Austrian company i386 when doing a bit of a scout around for some open source <a href="http://blog.webdistortion.com/2009/02/16/10-stonking-email-marketing-systems-reviewed/">email marketing solutions</a>. Its a C# system that could probably do with some community support, with the last checkin April 2008.  They need a bit of a hand out with some language translation, so if any of you guys are german speakers, (Austrian German) maybe you could be of use.</p>
<p>The application can run on MSDE/MS SQL and Access, and is on version 2.0 of the framework.</p>
<h4>YetAnotherForum</h4>
<p><strong>URL:</strong><a href="http://www.yetanotherforum.net/"> http://www.yetanotherforum.net/</a></p>
<p><a href="http://www.yetanotherforum.net"><img title="yetanotherjpg" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/yetanotherjpg.jpg" alt="yetanotherjpg" width="217" height="163" /></a></p>
<p><strong>S</strong><strong>ource Code: </strong><a href="http://sourceforge.net/project/showfiles.php?group_id=90539">Grab the source code here.</a></p>
<p>YAF was introduced to me through <a href="http://www.codefixer.com">Michael at Codefixer</a>. It seems like a pretty solid, well architected system, and has a vibrant and active open source community contributing to it’ success. In addition to a stand alone system, it also has a DotNetNuke and Rainbow Portal, which I’ve mentioned here.</p>
<p>If you haven’t already guessed YAF is a Open Source discussion forum or bulletin board system for web sites running ASP.NET. The latest production version runs on ASP.NET v2.0 with a Microsoft SQL Server backend. It is licensed under the GPL.</p>
<h4>DotNetNuke</h4>
<p><strong>URL:</strong> <a href="http://www.dotnetnuke.com">http://www.dotnetnuke.com</a></p>
<p><strong>Source Code: </strong><a href="http://www.dotnetnuke.com/tabid/125/default.aspx">Grab the source code here</a><strong><br />
</strong></p>
<p><a href="http://www.dotnetnuke.com"><img title="dotnetnuke" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/dotnetnuke.jpg" alt="dotnetnuke" width="222" height="166" /></a></p>
<p>DotNetNuke is an open source web application framework ideal for creating, deploying and managing interactive web, intranet, and extranet sites securely.</p>
<p>It has received it’s criticisms, including being accused of being bloated and a bit of a hungry beast, however over the last five years, DotNetNuke has established itself as a force to be reconned with.  It has become an essential framework within many business environments, and has released a professional commercial product which is a testament to the community achievement.</p>
<p>The quality and flexibility of the code base, combined with a very active and supportive community, has resulted in hundreds of thousands of deployments.</p>
<h4>Rainbow Portal</h4>
<p><strong>URL:</strong> <a href="http://www.rainbowportal.net/">http://www.rainbowportal.net/</a></p>
<p><strong>Source Code:</strong> <a href="http://sourceforge.net/project/showfiles.php?group_id=66837">Grab the source code here</a></p>
<p><a href="http://www.rainbowportal.net"><img title="rainbow" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/rainbow.jpg" alt="rainbow" width="219" height="164" /></a></p>
<p>Rainbow Portal is the rebel breakaway / fork project from DotNetNuke. They were the underdogs in the portal wars.  That said however, their systems are built in C# as opposed to VB, and things are done a bit differently, depending on your needs that might be ok. There is always things to be learned from other people’s coding examples.</p>
<p>My own thoughts are  that it may suit you if you are using C# to code, however the alternative MojoPortal project seems to be gaining traction.  The last release of Rainbow was way back in 2006. Mojo Portal’s last release was 26th Feb 2009.</p>
<h4>MojoPortal</h4>
<p><strong>URL:</strong> <a href="http://www.mojoportal.com/">http://www.mojoportal.com/</a></p>
<p><a href="http://www.mojoportal.com"><img title="mojoportal" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/mojoportal.jpg" alt="mojoportal" width="220" height="164" /></a></p>
<p><strong>Source Code: </strong><a href="http://mojoportal.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=23828">Grab the source code here</a></p>
<p>Mojo Portal appears to be receiving alot of attention recently. This can probably be attributed partially to the wide variety of database platforms which it runs on.</p>
<p>Separation of database concerns is one sign of a well architected project, and whilst I can’t personally vouch for the code, it looks like one to keep an eye on. They have a focus on creating standards compliant frontend HTML, and for that reason, they get my thumbs up. Both Rainbow Portal and DNN tended to create code which was very heavily table based, which lead to skinning difficulty. This seems to have been addressed within Mojo Portal.</p>
<h4>Oxite</h4>
<p><strong>URL: </strong><a href="http://visitmix.com/Lab/Oxite">http://visitmix.com/Lab/Oxite</a></p>
<p><strong>Source Code:</strong> <a href="http://www.codeplex.com/oxite">Grab the source code here</a></p>
<p><a href="http://visitmix.com/Lab/Oxite"><img title="oxite" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/oxite.jpg" alt="oxite" width="218" height="165" /></a></p>
<p>Oxite is an open source, web standards compliant, blog engine built on ASP.NET MVC. It is fully featured and includes support for all the blogging features you would expect.</p>
<p>Born out of a necessity to showcase Microsoft’s muscle in the blogging scene, Oxite provides example of ‘core blog functionality’ in a reusable way. The entire <a href="http://www.visitmix.com/">VisitMIX </a>site runs on Oxite, which just shows the potential quality of the finished product. I love the effort that they have put into the design of MIX, and for once, we are able to show others a production Microsoft site running a Microsoft product that really shines visually.</p>
<h4>nopCommerce</h4>
<p><strong>URL: </strong><a href="http://www.nopcommerce.com/">http://www.nopcommerce.com/</a></p>
<p><strong>Source Code: </strong><a href="http://http://www.nopcommerce.com/Downloads.aspx">Grab the source code here</a><strong><br />
</strong></p>
<p><a href="http://www.nopcommerce.com"><img title="nopcommerce" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/nopcommerce.jpg" alt="nopcommerce" width="221" height="165" /></a></p>
<p>Running on C# nopCommerce is a fully customizable shopping cart. It’s stable and highly usable. nopCommerce is a open source e-commerce solution that is ASP.NET 3.5 based with a MS SQL 2005 backend database.</p>
<p>It is pretty feature packed when you take a look around the system, and should serve as a good platform to build on for some developers. Whilst they aren’t over on the MVC system they have taken care of some of the problems with querystrings, and include a URL rewrite module.</p>
<p>Most developers should be able to get up and running quickly, simply change your web.config in a few places and the autoinstaller should get you going. well worth investigating if you are a .NET developer with a background in e-commerce.</p>
<h4>Kigg</h4>
<p><strong>URL:</strong> <a href="http://www.codeplex.com/Kigg">http://www.codeplex.com/Kigg</a></p>
<p><strong>Source Code: </strong><a href="http://kigg.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22690">Grab the source code here</a></p>
<p><a href="http://www.codeplex.com/kigg/"><img title="kigg" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/kigg.jpg" alt="kigg" width="220" height="165" /></a></p>
<p>KiGG is a Web 2.0 style social news web application developed in Microsoft supported technologies. It is an alternative to Pligg, which has gained significant niche adoption on the web.</p>
<p>It utilises the MVC pattern, and a number of other open source libraries &#8211; including the <a href="http://www.codeplex.com/entlib">Microsoft Patterns and Practises library</a> for it’s logging and caching. I’m a big fan of the Enterprise library, and I’ve used the security module for a few projects myself. Kigg has been developed with a TDD approach and uses <a href="http://www.codeplex.com/xunit">xUnit.Net</a> for it’s unit testing framework and <a href="http://code.google.com/p/moq/">Moq</a> as a mocking library. <a href="http://dotnetshoutout.com">DotNetShoutout</a> amongst other’s uses it extensively as the framework to run the site.</p>
<h4>SharpWebMail</h4>
<p><strong>URL: </strong><a href="http://anmar.eu.org/projects/sharpwebmail/">http://anmar.eu.org/projects/sharpwebmail/</a></p>
<p><strong>Source Code: </strong><a href="http://sourceforge.net/project/showfiles.php?group_id=108867">Grab the source code here.</a></p>
<p><a href="http://anmar.eu.org/projects/sharpwebmail/"><img title="sharpwebmail" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/sharpwebmail.jpg" alt="sharpwebmail" width="220" height="165" /></a></p>
<p>Whilst it aint the prettiest in the group &#8211; SharpWebMail is an established project which is written in C#, it uses a POP3 or IMAP servers as the mailstore and sends mail through a SMTP server. It is the only open source webmail solution for the .NET platform that I am aware of.</p>
<p>If you are a good user interface designer, and have never contributed to an open source project before, this would offer a great way to establish a name for yourself. Alternatively, adding a skinning engine to the project would probably be a help.</p>
<p>SharpWebMail is Licensed under GNU GPL.</p>
<h4>DotNetShoppingCart</h4>
<p><strong>URL: </strong><a href="http://www.dotshoppingcart.com/">http://www.dotshoppingcart.com/</a></p>
<p><strong>Source Code: </strong><a href="https://www.dotshoppingcart.com/Login.aspx?ReturnUrl=/Page/Community/Download.aspx">Grab the source code here.</a></p>
<p><a href="http://www.dotshoppingcart.com/"><img title="dotnetcommerce" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/dotnetcommerce.jpg" alt="dotnetcommerce" width="214" height="160" /></a></p>
<p>DotShoppingCart is an ASP.NET open source CMS &amp; eCommerce software. It enables businesses to manage site content and sell products and services through an online storefront. Unfortunately this was one of the ones I missed on my <a href="http://blog.webdistortion.com/2008/05/03/9-kick-ass-open-source-e-commerce-platforms-reviewed/">open source e-commerce post</a>.</p>
<p>DotShoppingCart open source edition is licensed under DotShoppingCart Public License. It’s basically a <a href="http://www.mozilla.org/MPL/MPL-1.1.html">MPL 1.1</a> plus the DotShoppingCart powered logo requirement on every single page.</p>
<p>If you are a developer looking to customise this one extensively, you will have to shell out for a Commercial license. That said, if you are looking for a cost effective route to market this one is worth examining a bit closer. As with nopCommerce, the feature list seems pretty extensive.</p>
<h4>BlogEngine.NET</h4>
<p><strong>URL: </strong><a href="http://dotnetblogengine.net">http://dotnetblogengine.net</a></p>
<p><strong>Source Code: </strong><a href="http://blogengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=14988">Grab the source code here</a></p>
<p><a href="http://dotnetblogengine.net"><img title="blogengine" src="http://blog.webdistortion.com/wp-content/uploads/2009/03/blogengine.jpg" alt="blogengine" width="212" height="160" /></a></p>
<p>BlogEngine.NET is an stable open source .NET blogging project. Touted as the next alternative to WordPress for .NET developers it integrates the best features of the .NET platform into its offering. It also has received backing from Redmond, and is featured on the <a href="http://www.asp.net/Downloads/starter-kits/blog-engine/">Microsoft.NET website as a Starter Kit</a>.</p>
<p>Personally, I haven’t used it much &#8211; the sheer amount of plugins for WordPress in comparison dwarf the project, and even for a code head like myself, it isn’t as appealing. That said, it may offer a way of integrating an existing .NET solution with a blogging engine. All the controls in BlogEngine.NET are 100% XHTML 1.0 compliant, which is great. The code base is C# ASP.NET 2.0.</p>
<h4>Best of the Rest.</h4>
<p><a href="http://www.dasblog.info/">DasBlog </a>- Open Source blogging Engine</p>
<p><a href="http://www.asp.net/community/projects/">Starter Kits and Community Projects</a> &#8211; Microsoft ASP.NET projects, good collection of Open source systems here.</p>
<p><a href="http://subtextproject.com/">SubText</a> &#8211; Another blog Engine</p>
<p><a href="http://hydrogencms.codeplex.com/">Hydrogen CMS</a> &#8211; A .NET Open source System</p>
<p><a href="http://code.google.com/p/dotnetkicks/">DotNETKicks</a> &#8211; Similar to KIGG, only not.</p>
<p><a href="http://www.evolutility.org/">EvolUtility</a> &#8211; A CRUD Framework</p>
<p><a href="http://code.google.com/p/sutekishop/">Suteki Shop</a> &#8211; Another e-commerce open source MVC app.</p>
<p>转载自：<a href="http://blog.webdistortion.com/2009/03/06/12-open-source-projects-for-net-you-probably-didn%E2%80%99t-know-about/">http://blog.webdistortion.com/2009/03/06/12-open-source-projects-for-net-you-probably-didn%E2%80%99t-know-about/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bookcold.com/2010/01/212/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->