Index
Below is a list of all posts created so far for the 2,000 Things You Should Know About C# blog.
Total number of posts = 1,219
Assemblies
- #11 – Examine IL Using Ildasm.exed
- #179 – What Is an Assembly?
- #180 – The CLR Loads Assemblies on Demand
- #485 – Project References and Dependent Assemblies
- #486 – Unnecessary Project References Are Ignored
- #705 – Applications and Class Libraries
- #706 – An Application Domain Enables Application Isolation
Basics
- #1 – What the Main() Signature Looks Like
- #2 – The Smallest Possible C# Program
- #3 – Who Designed C#?
- #4 – How is C# Different from Java?
- #5 – How is C# Different from VB.NET?
- #6 – An Even Smaller C# Program
- #8 – The Main() Function Can Return an int
- #9 – Main() Should Not Be Public
- #10 – The Return Value from Main() Sets ERRORLEVEL Variable in Windows
- #12 – Read Command Line Arguments
- #18 – What Is an Identifier?
- #19 – Contextual Keywords
- #20 – Literals
- #21 – Boolean Literals
- #22 – Integer Literals
- #23 – Real Literals
- #24 – Character Literals
- #26 – Null Literal
- #27 – Expressions, Operators and Operands
- #28 – Operator Precedence
- #29 – Comments
- #35 – Declaring Variables
- #36 – Variable Initialization and Definite Assignment
- #45 – Static Members of a Class
- #46 – There Is Only One Copy of Static Data
- #52 – Arithmetic Operators
- #53 – Modulus
- #54 – Increment and Decrement Operators
- #55 – Integer Division Results in Truncation
- #56 – How to Round When Converting Float to Int
- #67 – Default Behavior for Reference Type Equality
- #72 – Hexadecimal Numbers
- #73 – Bitwise Operators
- #74 – Shift Operators
- #75 – New Bits When Shifting
- #77 – Special Floating Point Values
- #78 – Check for Special Floating Point Values
- #79 – Equality Checks for NaN
- #83 – JIT Compilation in .NET
- #84 – Viewing Metadata as Source Code
- #85 – General Structure of a C# Program
- #86 – Equality and Inequality Operators
- #87 – Relational Operators
- #88 – Conditional Operators
- #89 – The Negation Operator
- #90 – More Complex Logical Expressions
- #91 – Conditional Operators Can Short-Circuit Evaluation
- #92 – The Ternary Conditional Operator
- #110 – Combining the Arithmetic Operators with the Assignment Operator
- #111 – Combining the Logical or Shift Operators with the Assignment Operator
- #117 – Use #define to Define a Symbol
- #118 – Disabling Specific Compiler Warnings
- #181 – C# Is Strongly Typed
- #182 – C# is (Mostly) Strongly Typed
- #183 – Use var to Tell the Compiler to Figure out the Type
- #184 – Cheating Type Safety with object Type
- #185 – The Heap and the Stack
- #186 – Value Types on the Heap
- #187 – Everything Is an Object
- #188 – Objects Are on the Heap, References to Objects Are on the Stack
- #189 – Memory Management for Stack-Based Objects
- #190 – Memory Management for Heap-Based Objects
- #199 – You Can’t Explicitly Delete Heap-Based Objects
- #200 – Static Data and Constants Are Stored on the Heap
- #201 – You Can Leak Memory in C#
- #202 – All Fields in an Object Are Automatically Initialized
- #204 – Three Rules About Using Implicitly-Typed Variables
- #205 – Five Kinds of Types That Are User-Definable
- #206 – Value Types Can’t Represent Null Values
- #207 – Nullable Types
- #208 – You Can Make Any Value Type Nullable
- #209 – Why You’d Want to Store a Null Value in a Variable
- #222 – C# Is Pronounced “C Sharp”
- #223 – Enabling Code Analysis for Your Project
- #224 – One Example of a Problem that Code Analysis Would Catch
- #225 – Free Static Analysis Using FxCop
- #371 – Delegate Basics
- #372 – What Delegates Are Good For
- #373 – A Delegate Can Refer to More than One Method
- #374 – A Custom Delegate Derives from System.MulticastDelegate
- #375 – Using GetInvocationList to Get a List of Individual Delegates
- #376 – What Happens When an Exception Occurs During Delegate Invocation
- #377 – Ensure that All of a Delegate’s Methods Are Called by Using GetInvocationList
- #385 – A Delegate Instance Can Refer to Both Instance and Static Methods
- #391 – Passing a Delegate Instance as a Parameter
- #401 – Every Object Inherits an Equals Method
- #402 – Value Equality vs. Reference Equality
- #403 – Equals Method vs. == Operator for Reference Types
- #404 – Equals Method vs. == Operator for Value Types
- #406 – Overriding the Equals Method
- #407 – Why You Should Override GetHashCode when Overriding Equals
- #411 – Overriding the Equals Method for a Value Type
- #413 – Check for Reference Equality Using Object.ReferenceEquals
- #417 – Provide a Type-Specific Equals Method for Value Equality
- #418 – Implementing the IComparable Interface
- #420 – Laundry List for Implementing Value Equality and IComparable
- #421 – Value Equality and IComparable Example
- #424 – The Garbage Collector
- #425 – Nondeterministic Destruction and Object Finalization
- #426 – Use a Destructor to Free Unmanaged Resources
- #427 – Finalizer Gotchas
- #428 – A Finalizer Should Always Call the Finalizer of Its Base Class
- #429 – Use the Dispose Pattern for Deterministic Destruction
- #430 – A Dispose Pattern Example
- #431 – The using Statement Automates Invocation of the Dispose Method
- #432 – Initialize Multiple Objects in a using Statement
- #467 – Metadata
- #468 – Attributes Allow Adding Metadata to Program Elements
- #469 – Attaching an Attribute to a Type Member
- #470 – Defining Your Own Custom Attribute
- #471 – Reading the Value of an Attribute Using Reflection
- #472 – Attributes Can Be Attached to a Variety of Elements
- #473 – Specifying what Type of Elements a Custom Attribute Can Be Applied To
- #475 – Comments Occuring within String Literals Are Treated as Part of the String
- #476 – Don’t Use Unicode Escape Sequences in Identifiers
- #499 – Conditional Compilation Symbols Are Defined or Undefined
- #500 – #define and #undef Must Be at Top of File
- #501 – Differences Between #define in C++ and C#
- #502 – #define and #undef Scope
- #503 – Conditionally Compile Code Using #if / #endif Directives
- #504 – Using the #else Directive
- #505 – Using the #elif Directive
- #506 – Using Expressions in #if and #elif Directives
- #507 – You can #define Other Symbols within a #if Block
- #508 – Using the #error and #warning Directives
- #509 – Use #pragma warning Directive to Disable Compile-Time Warnings
- #514 – Examples of Operator Precedence
- #515 – Binary Operators Are Left-Associative
- #516 – The Assignment Operator is Right-Associative
- #518 – Splitting the Implementation of a Class Across Multiple Files
- #521 – Namespaces Help Organize Types
- #522 – The Fully Qualified Name for a Type Includes the Namespace
- #523 – The using Directive Allows Omitting Namespace
- #524 – All Types Within a Namespace Must Be Unique
- #525 – Namespaces Can Be Nested
- #526 – Using Statements Can Alias Nested Namespaces
- #527 – Defining a Nested Namespace Using Dot Notation
- #529 – The using Directive Can Create an Alias for a Namespace
- #530 – Namespaces vs. Assemblies
- #531 – Best Practices for Naming Namespaces
- #532 – Using Identically Named Types from Different Assemblies
- #533 – Alternate Notation for Extern Aliases
- #535 – Creating a Generic Struct
- #542 – Conventions for Naming Type Parameters
- #543 – Operations You Can Perform on a Generically Typed Object
- #544 – Specifying a Constraint for a Type Parameter
- #545 – Specifying Constraints for More than One Type Parameter
- #550 – Anonymous Method Does Not Require Formal Parameters
- #551 – Use Anonymous Method When Adding to an Invocation List
- #552 – Anonymous Methods Have Access to Local Variables Where They Are Declared
- #583 – You Can’t Modify the Iterator Variable Within a foreach Loop
- #640 – Method Names that You Cannot Use
- #659 – Get Information About an Object’s Type
- #660 – The typeof Operator Gets Information About a Type
- #661 – Every Object Has A ToString Method
- #662 – Overriding the ToString Method for a Custom Type
- #664 – Physical Memory vs. Virtual Memory
- #665 – Maximum Amount of Virtual Memory
- #666 – Looking at .NET Memory Usage Using Performance Counters
- #667 – .NET Memory Performance Counters Updated When Garbage Collector Runs
- #668 – GetTotalMemory Indicates How Much Memory You’ve Allocated
- #673 – Types Used in using Statement Must Implement IDisposable
- #689 – References and Objects
- #707 – More Than One Class in A Program Can Contain A Main Method
- #709 – A Method Can Redefine a Name Present in Parent Class
- #710 – Variables Declared in a Block Aren’t Visible Outside of the Block
- #711 – The Global Namespace
- #712 – Accessibility Summary
- #713 – Declare Accessibility Explicitly
- #714 – Accessibility of a Public Method in an Internal Type
- #718 – Scope
- #721 – Local Variable Declarations Can Hide Class Members
- #722 – Local Variable Declarations May Not Always Hide Class Members
- #724 – Fully Qualified Names for Types
- #730 – Check for null Before Iterating Using foreach Statement
- #732 – Destruction vs. Collection
- #733 – How to Tell If an Object Has Been Garbage Collected
- #734 – Accessing the Original Object Referenced through a WeakReference
- #735 – Don’t Trust WeakReference.IsAlive If It Returns true
- #736 – Target of a WeakReference Will Be null after Garbage Collection
- #738 – You Shouldn’t Explicitly Force Garbage Collection
- #740 – Short vs. Long Weak References
- #771 – Summary of System.Object Members
- #803 – Situations When You Might Use the var Keyword
- #804 – Tradeoffs when Using the var Keyword
- #805 – An Example of Discretionary Use of the var Keyword
- #806 – An Example of Mandatory Use of the var Keyword
- #846 – A Call Stack Keeps Track of Methods that Have Been Called
- #847 – How the Call Stack Works
- #921 – Objects Are Explicitly Created but Automatically Destroyed
- #922 – Ways in Which References to an Object Are Released
- #923 – An Object Isn’t Necessarily Deleted as Soon as It’s Dereferenced
- #924 – You Shouldn’t Normally Worry about Memory Management
- #940 – Finalizers Are Called when an Application Shuts Down
- #941 – Checking to See If Objects Are Disposable
- #949 – What’s in Which Version of C#
- #950 – C# Has a Unified Type System
- #951 – Not Every Type Derives from object
- #952 – Type Safety
- #953 – Static Typing vs. Dynamic Typing
- #954 – Static Typing vs. Strongly Typed
- #955 – C# Is a Managed Language
- #956 – The Common Language Infrastructure (CLI)
- #957 – Naming Files that Contain C# Code
- #958 – Naming Conventions for Identifiers
- #959 – Don’t Use Double Underscores at the Start of an Identifier
- #960 – Conventions for Naming Classes
- #961 – Retrieving Command Line and Path to Executable
- #962 – Statements Can Span Multiple Lines
- #963 – Use Braces to Enclose a Block of Statements
- #964 – Declaring a Variable within a Block of Statements
- #965 – Indent Code to Improve Readability
- #966 – Visual Studio Code Editor Helps with Indenting
- #967 – Assigning a Value to a Variable
- #968 – Reading a Value from a Variable
- #969 – Creating a Simple Console Application
- #971 – Reading a Line of Input from the Console
- #972 – Reading Keystrokes from the Console
- #973 – Format Items in Composite Format Strings Can Be in Any Order
- #974 – Well Written Code Includes Well Written Comments
- #975 – Guidelines for Commenting Your Code
- #981 – Full List of C# Keywords
- #985 – Why It’s Useful for Conditional Operators to Short-Circuit Evaluation
- #987 – The using Directive Can Create an Alias for a Type
- #988 – Using global to Explicitly Refer to a Namespace
- #989 – Formatting Numbers as Hexadecimal
- #990 – Converting Hexadecimal Strings to Numeric Data
- #994 – Unicode Basics
- #995 – Unicode Code Points
- #996 – UTF-16 Encoding, Part I
- #997 – UTF-16 Encoding, Part II
- #998 – UTF-8 Encoding
- #999 – Some Examples of UTF-16 and UTF-8 Encoding
- #1,000 – UTF-8 and ASCII
- #1,001 – Representing Unicode Surrogate Pairs
- #1,002 – Specifying Character Encoding when Writing to a File
- #1,017 – Delegate Types vs. Delegate Instances
- #1,018 – Delegate Invocation Syntax
- #1,019 – Syntax for Adding Methods to a Delegate’s Invocation List
- #1,020 – Removing Methods from a Delegate’s Invocation List
- #1,021 – What Happens to a Delegate’s Return Value
- #1,022 – How to Use Return Values from All Delegate Instances
- #1,077 – The Decimal Numeral System
- #1,078 – The Hexadecimal Numeral System
- #1,079 – The Binary Numeral System
- #1,080 – Binary Numerals Written as Hexadecimal
- #1,081 – Bits, Bytes and Nibbles
- #1,082 – Big-endian and Little-endian
- #1,083 – Using Visual Studio to Verify Little-Endianness
- #1,084 – Representing Numbers Using Scientific Notation
- #1,085 – Binary Floating Point Numbers
- #1,086 – Converting Decimal Floating Point to Binary Floating Point
- #1,087 – Representing Binary Floating Point Numbers Using Scientific Notation
- #1,088 – How 32-Bit Floating Point Numbers Are Stored in .NET, part I
- #1,089 – How 32-Bit Floating Point Numbers Are Stored in .NET, part II
- #1,090 – Using Visual Studio to Verify How Floating Point Numbers Are Stored
- #1,091 – Subnormal Floating Point Numbers
- #1,092 – Positive and Negative Zero
- #1,093 – How Positive and Negative Zero Values Are Stored
- #1,094 – Positive and Negative Infinity
- #1,095 – How Floating Point Infinity Values Are Stored
- #1,096 – Floating Point NaN Values
- #1,097 – Summary of how Floating Point Numbers Are Stored in .NET
- #1,098 – Floating Point Overflow
- #1,099 – Overloading the Increment Operator
- #1,102 – Scope vs. Declaration Space
- #1,103 – A Block Defines Both Scope and Declaration Space
- #1,104 – Can’t Re-Declare a Variable within a Nested Block
- #1,105 – Re-Declaring a Class-Level Variable within a Method
- #1,112 – How Integers Are Stored in .NET
- #1,113 – Addition of Integers Using Twos Complement
- #1,127 – Where to Find Compiler Warning Numbers
- #1,128 – Disable a Compile-Time Warning for Entire Project
- #1,149 – Generic Delegate Types
- #1,150 – Generic Delegate Type as Parameter
- #1,151 – The Func Delegate Type
- #1,152 – The Action Delegate Type
- #1,153 – Different Delegate Types Are Not Assignment Compatible
- #1,154 – Input Parameter Compatibility when Assigning to Delegate Types
- #1,155 – Return Value Compatibility when Assigning to Delegate Types
- #1,156 – Covariance and Generic Delegate Types
- #1,157 – Contravariance and Generic Delegate Types
Classes
- #141 – Implementing ICloneable for a Custom Type
- #143 – An Example of Implementing ICloneable for Deep Copies
- #144 – Using Serialization to Implement Deep Copying
- #226 – Classes and Objects
- #227 – Instances of Classes Are Created on the Heap
- #228 – Object-Oriented Programming in C# Using Classes
- #229 – The Core Principles of Object-Oriented Programming
- #230 – User-Defined Types Are First Class Citizens
- #231 – Declaring and Using Instance Fields in a Class
- #232 – Declaring and Using Instance Methods in a Class
- #233 – Returning a Result from an Instance Method
- #234 – Multiple return Statements
- #235 – return Statement Is Not Needed for void Methods
- #236 – Returning a Reference Type from a Method
- #237 – Referencing Class Fields from Within One of its Methods
- #238 – Call a Method from Another Method
- #239 – The this Reference
- #240 – Private and Public Instance Data in a Class
- #241 – Declaring and Using Private Instance Methods
- #242 – Declaring and Using a Property in a Class
- #243 – Property Get and Set Accessors
- #244 – Defining a Get Accessor for a Property
- #245 – Defining a Set Accessor for a Property
- #246 – Implementing a Read-Only Property
- #247 – Implementing a Write-Only Property
- #248 – Implementing a Property that Returns a Calculated Value
- #249 – Using a get Accessor to Clean up Property Data
- #250 – Using a set Accessor to Convert or Validate Property Data
- #251 – Class Properties Support the Principle of Encapsulation
- #252 – Automatic Properties
- #253 – Implementing a Read-Only Automatic Property
- #254 – Implementing a Read-Only Property with a Private Set Accessor
- #255 – Static Fields vs. Instance Fields
- #256 – Using Static Fields
- #257 – Private Static Fields
- #258 – Initializing a Static Variable as Part of Its Declaration
- #259 – Static vs. Instance Properties
- #260 – How Properties Look Under-the-Covers
- #261 – How Automatic Properties Look Under-the-Covers
- #262 – Passing Data to a Method Using Parameters
- #263 – A Method’s Signature Must Be Unique Within Its Type
- #285 – Class Member Overview
- #286 – A Constructor is Called When an Instance of a Class Is Created
- #287 – You Don’t Have to Define a Constructor
- #288 – Passing Arguments to a Constructor
- #289 – You Can Define Multiple Constructors
- #290 – Chaining Constructors
- #291 – No Default Constructor if You Define any Constructors
- #292 – A Static Constructor Initializes Static Data
- #293 – You Can Declare a Private Constructor
- #294 – Make All Constructors Private to Prevent Object Creation
- #295 – When Is a Static Constructor Called?
- #299 – Intellisense Shows You Available Constructors
- #303 – Accessibility of Class Members
- #304 – Private Class Members
- #305 – Public Class Members
- #306 – Protected Class Members
- #307 – Internal Class Members
- #308 – Protected Internal Class Members
- #309 – Accessing Protected Members In a Derived Class
- #310 – Accessibility of Fields in a Class
- #311 – Accessibility of Properties in a Class
- #312 – Accessibility of Methods in a Class
- #313 – Accessibility of Constructors in a Class
- #314 – Access Modifiers Are Not Allowed on Static Constructors
- #315 – Accessibility of Static Methods and Properties
- #322 – Class Accessibility
- #323 – A Generic Class is a Template for a Class
- #324 – A Generic Class Can Have More than One Type Parameter
- #325 – Intellisense Understands Generic Classes
- #326 – Generic Type vs. Constructed Type
- #329 – A Class Can Inherit Data and Behavior from Another Class
- #330 – Derived Classes Do Not Inherit Constructors
- #331 – Calling a Base Class Constructor Implicitly vs. Explicitly
- #332 – Every Class Inherits from Exactly One Class
- #333 – Class Inheritance Leads to a Hierarchy of Classes
- #334 – A Base Class Variable Can Refer to Instances of Derived Classes
- #335 – Accessing a Derived Class Using a Base Class Variable
- #336 – Declaring and Using a readonly Field
- #337 – Declaring and Using Static readonly Fields
- #338 – Static Readonly Fields vs. Constants
- #339 – Readonly Fields vs. Read-Only Properties
- #342 – Using a Static Variable to Count Instances of a Class
- #343 – Use the new Keyword to Replace a Method in a Base Class
- #344 – Hidden Base Class Member Is Invoked Based on Declared Type of Object
- #345 – Method in Derived Class Hides Base Class Method by Default
- #346 – Polymorphism
- #347 – Another Example of Polymorphism
- #348 – Virtual Methods Support Polymorphism
- #349 – The Difference Between Virtual and Non-Virtual Methods
- #350 – Method Modifiers Required for Polymorphic Behavior
- #351 – An Abstract Method Has No Implementation
- #352 – You Can’t Instantiate an Abstract Class
- #353 – Why You Might Define an Abstract Class
- #355 – Use the new Keyword to Replace a Property in a Base Class
- #356 – Hidden Base Class Property Is Used Based on Declared Type of Object
- #357 – Property in Derived Class Hides Base Class Property by Default
- #358 – Virtual Properties Support Polymorphism
- #359 – The Difference Between Virtual and Non-Virtual Properties
- #360 – Property Modifiers Required for Polymorphic Behavior
- #361 – An Abstract Property Has No Implementation
- #362 – Defining an Indexer
- #363 – An Indexer Can Have Both get and set Accessors
- #364 – Defining an Indexer whose Parameter Is an Enumerated Type
- #365 – Overloading an Indexer
- #366 – Defining an Indexer with More than One Parameter
- #517 – Static Classes
- #534 – What Good Are Generics?
- #546 – Specifying More than One Constraint for the Same Type Parameter
- #547 – Things That Can Serve as Type Parameter Constraints
- #548 – No More Than One Class for a Type Parameter Constraint
- #567 – Wider vs. Narrower Types
- #570 – Assignment Compatibility for Reference Types
- #590 – Optional Parameters in Constructors
- #601 – A Class Can Both Inherit from A Parent Class and Implement an Interface
- #602 – Initializing Fields in a Class
- #603 – Using Constants Can Force Recompilation
- #609 – Omit the Class Name for Static Members in the Same Class
- #610 – Lazy Evaluation in Property Get Accessors
- #614 – Subclass Accessibility
- #615 – You Can’t Remove a Base Class Member
- #616 – Base Class Needs to Know If Polymorphism Is Desired
- #617 – The Simplest Way to Call a Method in a Base Class
- #618 – Use the base Keyword to Call A Method in the Base Class
- #619 – Calling the Constructor in a Base Class
- #620 – Inherit from a Class In A Different Assembly
- #621 – Sealing a Class to Prevent Inheritance
- #622 – Sealing vs. Not Sealing
- #623 – Defining One Type Inside Another Type
- #624 – Accessibility of a Nested Class
- #625 – Reference a Nested Type Using Dot Notation
- #626 – Nested Type Options
- #627 – Accessibility of Nested Types in a struct or a class
- #628 – Why You Might Create a Nested Type
- #629 – Nested Types Have Full Access to Members in Parent
- #630 – Nested Type May Hide Member in Outer Class
- #631 – Code-Generation Tools and Partial Classes
- #639 – Static Class Can Contained Nested Non-Static Class
- #648 – Using an Object Initializer
- #649 – Creating an Anonymous Type
- #655 – Initializing Only Some Properties with An Object Initializer
- #656 – Nested Object Initializers
- #669 – Initializing Fields by Calling A Method
- #670 – Static vs. Instance Initialization
- #671 – A Base Class Constructor Can Call a Virtual Method
- #675 – Polymorphic Behavior Requires virtual / override Combination
- #676 – An Overridden Method Can Itself Be Overridden
- #677 – Method Marked with new Modifier Cannot Be Overridden
- #678 – A Sealed Method Cannot Be Overridden
- #679 – Hide An Inherited Method with A Virtual Method
- #680 – Virtual Modifier Combinations
- #681 – Avoid Using the new Keyword To Hide Methods
- #682 – The Real Reason for the new Keyword
- #683 – Two Ways an Object Can Behave Polymorphically
- #684 – Hidden Base Class Members Aren’t Really Hidden
- #685 – Inheritance Can Break Encapsulation
- #686 – Inheritance vs. Containment
- #687 – An Example of Containment
- #688 – Aggregation, Composition and Containment
- #690 – Using the this Keyword To Distinguish Between Fields and Parameters
- #692 – Two Approaches for Optional Parameters in Constructors
- #693 – Named Arguments in Constructors Allow the Most Flexibility
- #694 – Sequence of Events for Chained Constructors
- #696 – Using a Static Property to Count Instances
- #697 – Encapsulation is Managed through the Use of Access Modifiers
- #698 – Type Members Are Implicitly Private
- #699 – Types Are Implicitly Internal
- #700 – Using a set Accessor To Enforce Casing
- #701 – Centralize Business Rules Logic in set Accessors
- #702 – An Automatic Property Must Define Both get and set Accessors
- #703 – Object Initializers Allow Setting Either Fields or Properties
- #704 – Using an Object Initializer with Any Constructor
- #708 – A Name Must Be Unique Within A Declaration Space
- #715 – Private Members Are Not Visible in a Derived Class
- #716 – How Derived Classes Can Access Protected Members
- #717 – Class Members Can’t Be More Accessible Than Their Type
- #719 – Location of Declarations within A Class Doesn’t Matter
- #720 – Location of Declarations within A Method Does Matter
- #723 – New Methods in Subclass May Not Be Visible in Derived Classes
- #737 – When to Implement a Finalizer
- #739 – Avoid Accessing an Object After Its Been Finalized
- #741 – The Basics of Inheritance
- #742 – A Simple Example of Inheritance
- #744 – The Purpose of Inheritance
- #751 – Inheritance Only Partially Preserves Encapsulation
- #752 – C# Does Not Support Multiple Inheritance
- #753 – Implicitly Upcast to a Base Class Reference
- #754 – Downcast to a Reference to a Derived Class
- #768 – When to Call the Constructor of a Base Class
- #769 – Pattern – Call a Base Class Method When You Override It
- #783 – When to Create a Static Class
- #784 – When Not to Use a Static Class
- #787 – Avoid Public Fields in a Class
- #788 – A Backing Field Stores Data for a Property
- #790 – Property get and set Accessors Can Have Different Access Modifiers
- #791 – Properties Are Not Variables
- #795 – Rules for Creating an Immutable Class
- #796 – Default Accessibility for Property Accessors
- #797 – Setting Accessibility for Property Accessors
- #798 – You Can’t Override Accessors that Are Not Accessible
- #800 – A Property in an Interface May Include One or Two Accessors
- #801 – An Example of a Simple Immutable Class
- #817 – What Happens When a Static Constructor Throws an Exception
- #818 – What Happens When an Instance Constructor Throws an Exception
- #819 – A Private Constructor May Prevent Inheritance
- #820 – A Protected Constructor Allows a Subclass to Create Instances
- #824 – A Copy Constructor Makes a Copy of an Existing Object
- #825 – Shallow Copies
- #826 – Deep Copies
- #827 – Making a Deep Copy with a Copy Constructor
- #828 – Implementing Both a Copy Constructor and ICloneable
- #829 – Add Comments to Indicate Shallow vs. Deep Copying
- #830 – The Problem with ICloneable
- #831 – Implementing a Copy Constructor in a Derived Class
- #832 – The Sequence in Which Finalizers Are Called
- #1, 023 – Fields Are Initialized Before Execution of Constructors
- #1,024 – Exposing internal Members to Another Assembly
- #1,027 – Type Parameters vs. Type Arguments in a Generic Class
- #1,028 – Generic Types vs. Generic Methods
- #1,029 – How to Define a Constructor in a Generic Type
- #1,030 – Requiring Generic Type Parameters to Derive from a Specified Class
- #1,031 – Requiring Generic Type Parameters to Implement an Interface
- #1,032 – Requiring Generic Type Parameters to Be a Reference or Value Type
- #1,033 – Requiring a Generic Type Parameter to Have a Parameterless Constructor
- #1,034 – Making One Type Parameter Depend on Another
- #1,035 – Summary of Type Parameter Constraints
- #1,036 – Specifying Multiple Type Parameter Constraints
- #1,037 – Specifying Type Parameter Constraints for More than One Type Parameter
- #1,039 – Deriving from a Generic Class
- #1,040 – Deriving from a Constructed Type
- #1,041 – Adding New Type Parameters when You Derive from a Generic Class
- #1,042 – Deriving from a Self-Referencing Constructed Type, Part I
- #1,043 – Deriving from a Self-Referencing Constructed Type, part II
- #1,044 – How Static Data Behaves in Generic Types
- #1,070 – A Generic Type Can Be Compiled
- #1,134 – Use “of” Terminology for Generics
- #1,135 – Overloading a Generic Class
- #1,137 – Generic Methods in Non-Generic Classes
- #1,138 – Type Parameters in Generic Methods Can Be Constrained
- #1,139 – The Problem with Comparisons of Objects in Generic Types
- #1,140 – Comparing Reference-Typed Objects in Generic Types
- #1,141 – Reference Equality Used Even when Overload Available for Typed Parameter
- #1,142 – Using EqualityComparer to Compare Objects in Generic Types
- #1,143 – Implement IEquatable in a Generic Type
- #1,144 – Getting Type Information about a Generic Type
- #1,145 – Using Reflection on Generic Type Parameters
- #1,146 – Generics Don’t Support Covariance
- #1,147 – Why Generics Don’t Support Covariance
- #1,148 – When to Use a Generic Covariant Interface
Collections
- #423 – Compare Two Lists Using SequenceEquals
- #842 – The Stack Data Type
- #843 – Using the Generic Stack Class
- #844 – The Queue Data Type
- #845 – Using the Generic Queue Class
- #1,117 – foreach Requires IEnumerable Implementation
- #1,118 – foreach Works with Iterator Returned by yield
- #1,129 – Generic Dictionary Basics
- #1,130 – Checking to See if a Generic Dictionary Already Contains a Key
- #1,131 – Example of Using a Generic Dictionary
- #1,132 – Using a SortedDictionary
- #1,133 – Initializing a Dictionary with a Collection Initializer
Data Types
- #30 – Types, Variables, Values, Instances
- #31 – Value Types and Reference Types
- #32 – Built-In Types
- #34 – The object Type
- #37 – All Value Types Have a Default Constructor
- #38 – Data Type Hierarchy
- #39 – MinValue / MaxValue for Numeric Types
- #40 – TrueString and FalseString
- #41 – Instantiating Reference Types
- #42 – Interacting With an Object
- #43 – Objects Are Instantiated on the Heap
- #44 – Multiple References to the Same Object
- #47 – Numeric Conversions Through Casting
- #48 – How Explicit Casts Fail
- #49 – When to Use the Decimal Type
- #50 – Static Methods of System.Char
- #51 – Float Literals Must Use f Suffix
- #57 – Overflow on Integer Operations
- #58 – Generate Exceptions on Integer Overflow Using Checked Operator
- #59 – Using Unchecked Keyword to Avoid Overflow Exceptions
- #76 – Arithmetic Operations with Small Integers
- #80 – Use Decimal Type for Monetary Calculations
- #81 – DateTime and TimeSpan Types
- #82 – Some Common DateTime and TimeSpan Functions
- #93 – Escape Sequences in Character Literals
- #94 – Converting Between Char and Numeric Types
- #107 – Defining and Using a Struct
- #108 – Defining a Constructor for a Struct
- #109 – Defining and Using Enums
- #119 – Arrays
- #120 – Array Declaration and Instantiation
- #121 – Array Initialization
- #122 – Arrays Can Contain Any Type of Object
- #123 – Storing Arbitrary Objects in an Array
- #124 – Declaring and Instantiating Multidimensional Arrays
- #125 – Initializing Multidimensional Arrays
- #126 – Initializing Arrays of Reference-Type Objects
- #127 – Declaring and Instantiating Jagged Arrays
- #128 – Accessing Elements in Jagged Arrays
- #129 – Initializing Jagged Arrays
- #130 – Default Values of Array Elements
- #131 – Arrays Derive from System.Array
- #132 – Arrays That Are Both Multidimensional and Jagged
- #133 – An Array’s Length is Fixed
- #134 – Sorting One-Dimensional Arrays
- #135 – Implement IComparable to Allow Sorting a Custom Type
- #136 – Sorting an Array of Values Based on an Array of Keys
- #137 – Sorting an Array Using an Independent Comparer Method
- #138 – Searching a Sorted Array
- #139 – Using the Array.Clone Method to Make a Shallow Copy of an Array
- #140 – Making a Deep Copy of an Array Using an Object’s Clone Method
- #142 – Implement ICloneable All the Way Down for Deep Copies
- #145 – Using Array.Find to Search an Unsorted Array
- #146 – Using Array.FindAll to Find a Set of Matching Elements in an Array
- #147 – Getting the Average of an Array of Numbers
- #148 – Getting the Average of an Array of Custom Objects
- #149 – Using IEnumerable.Aggregate to Perform a Calculation Based on All Elements in an Array
- #150 – Other Aggregate Functions You Can Apply to Numeric Arrays
- #151 – Determining Whether an Array Contains a Specific Element
- #152 – Remove Duplicate Array Entries Using Distinct() Method
- #153 – Returning a Subset of Array Elements Matching a Particular Criteria
- #154 – Using an Invalid Array Index Causes an Exception to Be Thrown
- #155 – Iterating Through An Array Using the foreach Statement
- #156 – Using break and continue in foreach Loops
- #191 – Changing the Underlying Type of an enum
- #192 – Using Non-Default Constant Values for Enumeration Members
- #193 – An Enum Type’s ToString Method Displays the Member’s Name
- #194 – Storing a Set of Boolean Values as Bits
- #195 – Using an Enum Type to Store a Set of Flags
- #196 – Using the ToString() Method on a Flags-Based Enum Type
- #197 – Checking an Enumerated Value for the Presence of a Flag
- #198 – Enumeration Values That Set Combinations of Flags
- #203 – It’s Good Practice to Always Have a 0-Valued Enumeration Constant
- #210 – Checking to See Whether a Nullable Object Has a Value
- #211 – Using the Null-Coalescing (??) Operator
- #212 – Using Several Null-Coalescing (??) Operators in the Same Expression
- #213 – Final Operand When Using Null-Coalescing (??) Operator
- #214 – Using the Null-Coalescing (??) Operator with Reference Types
- #215 – Using the Null-Coalescing (??) Operator with Custom Nullable Types
- #216 – Null-Coalescing (??) Operator Is Equivalent to GetValueOrDefault Method
- #217 – T? Is Equivalent to Nullable<T>
- #218 – Store Value-Typed Objects on the Heap Through Boxing
- #219 – Unboxing a Boxed Object
- #220 – Boxing Can Happen Automatically
- #221 – When Unboxing, You Must Match the Original Type Exactly
- #280 – Implicitly-Typed Arrays
- #296 – You Must Assign a Value to All Fields Before Using a struct
- #297 – Three Different Ways to Initialize the Contents of a struct
- #298 – A struct Can Have Several Constructors
- #316 – Declaring and Using Constants
- #317 – Constants Can Be Class Members
- #318 – You Can’t Use the static Modifier On a Constant
- #319 – You Initialize a Constant Using an Expression
- #320 – The Constant Expression for a Reference-Typed Constant Must Be Null
- #321 – Accessibility of Constants
- #327 – Assigning a struct to a New Variable Makes a Copy
- #328 – Copying a struct Will Not Copy Underlying Reference Types
- #367 – Iterating through All Possible Values of an Enumeration Type
- #433 – All structs Inherit from System.ValueType
- #457 – Converting Between enums and their Underlying Type
- #458 – Errors While Converting Between enum and Underlying Type
- #459 – Assigning a Value of a Different Type to an enum
- #460 – Converting from a String to an Enum Type
- #461 – Enumeration Elements Don’t Need to Be Sequential
- #462 – Duplicate Enumerators in an Enumerated Type
- #463 – Enumerated Values Can Be Any Constant Expression
- #464 – Getting an Enumeration’s Underlying Type at Runtime
- #465 – Dumping All Names and Values for an Enumerated Type
- #466 – Explicitly Assigning Only Some Enumerated Values
- #477 – Full List of Escape Sequences for Character Literals
- #510 – Declaring More than One Local Variable On the Same Line
- #519 – Differences Between structs and classes
- #520 – Choosing Between a struct and a Class
- #566 – Implicit Conversions to Nullable Types
- #568 – Array Covariance
- #569 – Assignment Compatibility
- #571 – Covariance in Programming Languages
- #572 – Why Array Covariance Is Called Covariance
- #573 – Array Covariance Doesn’t Apply to Value Types
- #574 – The Problem with Array Covariance
- #581 – Boxing and Unboxing Nullable Types
- #582 – Use the as Operator to Unbox to a Nullable Type
- #596 – Implicitly-Typed Arrays and Best Type Inference
- #598 – Clearing an Array or a Subset of an Array
- #599 – Copying an Array Onto Another Array
- #600 – Reversing the Elements in an Array
- #611 – Accessibility of Members in a struct
- #641 – Using the this Keyword in a struct
- #642 – Reassigning the this Pointer in a struct
- #643 – The Constructor for a struct Must Initialize All Data Members
- #644 – Chaining struct Constructors
- #645 – You Can Chain to the Default Constructor for a struct
- #646 – Value Types Don’t Have Finalizers
- #650 – Creating an Array of Anonymously-Typed Objects
- #651 – Passing an Anonymously-Typed Object to a Method
- #652 – Using Expressions and Variables in Anonymous Type Declarations
- #653 – Projection Initializers
- #654 – You Can’t Use an Anonymous Type Directly
- #657 – Boxing Makes a Copy of An Object
- #658 – What Boxing and Unboxing Look Like in IL
- #767 – A struct Is Implicitly Sealed
- #775 – Copying an Array of Anonymously-Typed Objects
- #776 – Declaring and Using Nullable structs
- #777 – A struct Isn’t Mutable When Used as a Property
- #778 – A struct Isn’t Mutable When Used in a Collection
- #779 – Methods in struct that Modify Elements Can Be Dangerous
- #780 – The Case for Immutable structs
- #781 – A struct Can Implement an Interface
- #782 – You Can Create an Instance of a struct Without the new Keyword
- #789 – Grouping Constants into Their Own Class
- #833 – Some Examples of Anonymous Object Initializers
- #834 – Use a Generic List to Store a Collection of Objects
- #835 – A Generic List Can Store Value-Typed or Reference-Typed Objects
- #836 – Initializing a Generic List with an Object Initializer
- #837 – Object Initializers within Collection Initializers
- #838 – Object and Collection Initializers as Parameters
- #839 – Anonymous Type Limitations
- #840 – Use an Anonymous Type as a Read-Only Subset of an Object
- #982 – An Enum Type Can Store a Maximum of 32 Flags
- #983 – Using a BitArray to Store a Large Collection of Boolean Values
- #991 – Using the Round-Trip Format Specifier
- #992 – The System.Char Data Type
- #993 – Some Examples of Characters
- #1,012 – Options for Array Declaration, Instantiation and Initialization
- #1,013 – default Operator Returns Default Values
- #1,014 – Using default Operator in a Generic Class
- #1,015 – Rendering a Byte Array as a Series of Hex Characters
- #1,016 – Retrieving the Length of an Array
- #1,025 – Converting between enum Types
- #1,026 – Checking a Flagged enum Type for Validity
- #1,045 – Implicit Conversions When Assigning from a Nullable Type
- #1,046 – Implicit vs. Explicit Conversions
- #1,047 – The Implicit Identity Conversion
- #1,048 – No Implicit Conversions between Signed vs. Unsigned
- #1,049 – Full List of Implicit Numeric Conversions
- #1,050 – Implicit Conversions between Nullable Types
- #1,051 – Implicit Reference Conversions
- #1,052 – Boxing Is a Kind of Implicit Conversion
- #1,053 – Implicit Conversion from Type dynamic
- #1,054 – Implicit Conversions from Constant Expressions
- #1,055 – Defining Your Own Implicit Conversions
- #1,056 – Custom Implicit Conversions between Reference Types
- #1,057 – Custom Explicit Conversions
- #1,058 – Custom Implicit Conversions in Both Directions
- #1,059 – Converting from Numeric to Enumerated Types
- #1,060 – Explicit Conversions between Nullable Types
- #1,061 – Explicit Reference Conversions
- #1,062 – Unboxing Conversions
- #1,063 – Explicit Conversions and Type Parameters
- #1,064 – Getting Around Inability to Explicitly Convert Type Parameters
- #1,065 – Cases When Array Covariance Doesn’t Work
- #1,066 – Constraining a Type Parameter on a Generic Interface
- #1,076 – Implicit Numeric Conversions from the char Type
- #1,111 – Converting an Integer to a String in a Different Base
- #1,198 – Using Operators with Nullable Types
- #1,199 – Equality and Inequality with Nullable Types
Debugging
- #112 – Conditionally Compiling Code in Debug Builds
- #491 – Use Debug.WriteLine to Output Debug Information
Enumeration
- #555 – Enumerable Objects and Enumerators
- #556 – Using an Enumerator Explicitly
- #557 – Using an Iterator to Return the Elements of an Enumerable Type
- #558 – Using an Iterator Within a for Loop
- #559 – An Iterator Can Return an Enumerable Type or an Enumerator
- #560 – Returning an Enumerator from an Iterator
- #561 – Using a yield break Statement
- #562 – What an Iterator Looks Like Under the Covers
- #563 – Enumerable Types Can Generate Multiple Enumerators
- #564 – Use the Reverse Method to Iterate Backwards through a Collection
- #565 – Using an Iterator to Return A Shuffled Sequence
- #1,193 – yield Statement and try/catch Blocks
- #1,194 – Chaining Iterators Together
- #1,195 – Iterator Produces Only as Many Elements as Are Needed
- #1,196 – Using Fluent-Style Syntax when Chaining Iterators
- #1,197 – Iterator Can Generate Enumerable of Infinite Length
Events
- #368 – How Events Work
- #369 – Multiple Clients Can Subscribe to the Same Event
- #370 – Subscribe to an Event by Adding an Event Handler
- #378 – Implementing an Event
- #379 – Using the EventHandler Delegate for Events that Return No Data
- #380 – Handling Events that Use the EventHandler Delegate Type
- #381 – Implementing an Event that Returns Some Data
- #382 – Handling an Event that Returns Some Data
- #383 – Removing a Handler from an Event
- #384 – The Difference Between Delegates and Events
- #386 – Implementing a Static Event
- #387 – Static Events vs. Static Event Handler Methods
- #388 – Declaring and Using Private Events
- #389 – Check for Null Before Raising an Event
- #390 – Using the Same Handler for Multiple Events
- #393 – Implement a Helper Method to Raise an Event
- #394 – Raising an Event in a Thread-Safe Manner
- #395 – Overriding the Default add and remove Accessors for an Event
- #1,158 – Events vs. Delegates, part I
- #1,159 – Events vs. Delegates, part II
- #1,160 – Implementing Events Defined in an Interface
- #1,161 – Explicit Implementation of Events in Interface
- #1,162 – Virtual Events Support Polymorphism
- #1,163 – An Abstract Event Has No Implementation
- #1,164 – A Sealed Event Cannot Be Overridden
Exceptions
- #672 – An Exception Thrown From a Finalizer Will Be Treated as an Unhandled Exception
- #841 – Exceptions
- #850 – Three Types of Errors that Can Lead to Exceptions
- #851 – A General Philosophy for Handling Exceptions
- #852 – How Exceptions Work
- #853 – An Exception Is an Instance of the System.Exception Class
- #854 – Catching an Exception
- #855 – Throwing an Exception
- #856 – Choosing an Exception Type to Throw
- #857 – What an Exception Object Contains
- #858 – Reading Exception Information in a Handler
- #859 – The Scope of a try Block
- #860 – Exceptions Bubble up the Call Stack
- #861 – A finally Block Always Executes
- #862 – Options for Including catch and finally Blocks
- #863 – How a finally Block Works with No catch Block
- #864 – An Example of a finally Block with No catch Block
- #865 – A catch Block Specifies the Type of Exception to Catch
- #866 – A catch Block Without Arguments Catches All Exceptions
- #867 – Including Several catch Blocks
- #868 – List Most Specific Exception Types First
- #869 – Example of Catching an Exception Thrown by the .NET Framework
- #870 – Where Execution Continues when an Exception Is Caught
- #871 – Where Execution Continues when an Exception Is Not Caught
- #872 – Code After a throw Statement Is Not Executed
- #873 – Full Example of Throwing and Catching an Exception
- #874 – An Exception Can Be Thrown from a Constructor
- #875 – Looking at the Call Stack after Catching an Exception
- #876 – Unhandled Exceptions
- #877 – Unhandled Exceptions on Background Threads
- #878 – Unhandled Exceptions in Static Constructors
- #879 – Unhandled Exceptions in Finalizers
- #880 – Catching Different Exception Types at Different Levels
- #881 – When to Throw Exceptions
- #882 – What Types of Exceptions to Throw
- #883 – Re-throwing an Exception
- #884 – Things You Might Do in an Exception Handler
- #885 – Getting Information about the Method that Threw an Exception
- #886 – Setting the HelpLink Property when You Throw an Exception
- #887 – Report Additional Data when You Throw an Exception
- #888 – Objects Added to Exception’s Data Dictionary Must Be Serializable
- #889 – Catching Exceptions that Derive from a Common Base Type
- #890 – Common System Exception Types that You Might Throw
- #891 – Example of Throwing a System Exception Type
- #892 – Creating a Custom Exception Type
- #893 – A Custom Exception Type Doesn’t Need to Add Custom Data
- #894 – Creating a Custom Exception Type with Custom Data
- #895 – Catching a Custom Exception Type
- #896 – Custom Exceptions Should Be Marked as Serializable
- #897 – Rules for Creating a Custom Exception Type
- #898 – Using Code Snippets to Implement a Custom Exception Type
- #899 – Exception Type Variable in a catch Block Is Optional
- #900 – What the Exception Object Contains when You Re-throw an Exception
- #901 – Throwing a New Exception from a catch Block
- #902 – Data Available to the Handler of a Wrapped Exception
- #903 – Wrapped Exceptions Can Be Several Levels Deep
- #904 – Getting the Innermost Wrapped Exception
- #905 – Examining an Exception’s Stack Trace
- #906 – Adding Custom Data vs. Using a Custom Exception Type
- #907 – Exceptions Thrown from Main Are Treated as Unhandled Exceptions
- #908 – Handling Unhandled Exceptions
- #909 – When a finally Block Executes
- #910 – One Example of a finally Block
- #911 – finally Block Execution When Exception Is Rethrown
- #912 – Intellisense Can Show Exceptions that a Method Might Throw
- #913 – How to Document that a Method Can Throw an Exception
- #914 – Using the Debugger to Break when an Exception Is Thrown
- #915 – An Exception Can Cross Assembly Boundaries
- #916 – Exception Can Cross .NET Language Boundaries
- #917 – Corrupted State Exceptions Are Not Normally Caught
- #918 – Catching Corrupted State Exceptions
- #919 – Think Twice about Handling Corrupted State Exceptions
- #920 – A finally Block Is Not Executed When a Corrupted State Exception Occurs
- #1,192 – Following the TryParse Pattern
Input/Output
Interfaces
- #434 – Interfaces
- #435 – Implementing an Interface
- #436 – The Implementation of an Interface Can Be a Subset of the Class
- #437 – Access Interface Members through an Interface Variable
- #438 – Benefits of Using Interfaces
- #440 – A Class Can Implement More than One Interface
- #441 – Implementing Interface Members Explicitly
- #442 – Explicit Interface Implementation Allows Duplicate Member Names
- #443 – An Interface Cannot Contain Fields
- #444 – Interfaces Can Inherit from Other Interfaces
- #445 – Differences Between an Interface and an Abstract Class
- #446 – Deciding Between an Abstract Class and an Interface
- #447 – Use as Operator to Get At an Object’s Interfaces
- #448 – Use the is Operator to See if an Object Implements an Interface
- #449 – You Can Pass an Interface Variable to a Method
- #450 – Interfaces Should Normally Start with the Letter ‘I’
- #451 – Implement Interface Explicitly to Simplify How a Class Appears to Clients
- #454 – Return an Interface as a Return Value from a Method
- #455 – Define an Interface Based on Existing Members of a Class
- #456 – Explicitly Implemented Interface Members Are Automatically Private
- #536 – Using a Generic Interface
- #537 – Implement a Generic Interface with a Generic Class
- #612 – Members of an Interface Are Implicitly Public
- #613 – Interfaces Cannot Contain Static Members
- #647 – A struct Can Implement an Interface
- #799 – Interface Members Are Implicitly Public
- #1,067 – Covariance and Generic Interfaces
- #1,068 – Generic IEnumerable Interface Is Covariant
- #1,069 – Contravariance and Generic Interfaces
Memory
- #604 – The Problem with Reading/Writing Shared Data from Different Threads
- #605 – The Causes of Problems With Reading/Writing Shared Data from Multiple Threads
- #606 – Use volatile Keyword to Fix Problems With Reading/Writing Shared Data
- #607 – When Do You Need the volatile Keyword?
- #925 – The Managed Heap
- #926 – How Memory Is Allocated for Objects on the Managed Heap
- #927 – Visualizing How Objects Are Created on the Managed Heap
- #928 – How Objects Are Removed from the Managed Heap
- #929 – Visualizing How Objects Are Removed from the Managed Heap
- #930 – Objects on the Heap Can Refer to Each Other
- #931 – Objects with Finalizers Take Longer to Garbage Collect
- #932 – When Objects Become Eligible for Garbage Collection
- #933 – The Garbage Collector Groups Objects into Generations
- #934 – How Generations Help the Garbage Collector Run More Efficiently
- #935 – Large Objects Are Allocated on the Large Object Heap
- #936 – Visualizing Garbage Collection Generations
- #937 – Forcing a Garbage Collection
- #938 – Finding Out What GC Generation an Object Is In
- #939 – Not All Objects on Heap Are Promoted to Next GC Generation
Methods
- #264 – By Default, Parameters Are Passed by Value
- #265 – Passing Reference Types by Value
- #266 – You Can’t Prevent a Method from Changing the Contents of Reference Types
- #267 – Passing Data Back from a Method Using out Parameters
- #268 – You Must Set the Value of All out Parameters Before Returning from a Method
- #269 – Use ref Modifier on Parameters that Are Input/Output
- #270 – Passing a Reference Type by Reference
- #271 – Passing a Reference Type as an Output Parameter
- #272 – Differences Between ref and out Parameters
- #273 – Parameter Modifier Summary
- #274 – Can’t Overload if Methods Differ Only by ref and out Modifiers
- #275 – Passing a struct to a Method
- #276 – Passing a struct by Reference
- #277 – Passing an Array to a Method
- #278 – Passing an Array by Reference
- #279 – Passing a Multidimensional Array to a Method
- #281 – Declaring and Using Static Methods in a Class
- #282 – Creating Private Static Methods
- #283 – Instance Methods Can Call Static Methods
- #284 – Static Methods Can Call Instance Methods
- #340 – Use the params Keyword to Pass a Variable Number of Arguments
- #341 – Defining and Using Local Variables
- #354 – Correct Overloaded Method Is Automatically Called
- #511 – Rules for Using Parameter Arrays
- #512 – Two Ways to Pass Data to a Method that Takes a Parameter Array
- #513 – Some Familiar Methods that Accept Parameter Arrays
- #538 – Implement a Generic Method
- #539 – Type Inference When Calling Generic Methods
- #540 – Non-Generic Methods in a Generic Class
- #541 – Generic Method Type Parameters Can Hide Class-Level Type Parameters
- #549 – Anonymous Method Basics
- #553 – Anonymous Methods as Static or Instance Methods
- #554 – Rules for Matching an Anonymous Method to a Delegate Type
- #584 – Defining an Optional Parameter
- #585 – Optional Parameters Must Come Last
- #586 – Default Values for Optional Parameters Must Be Constants
- #587 – If Provided, Optional Arguments Must Be in Correct Order
- #588 – A Default Parameter Value Can Be Null
- #589 – Optional Parameters Must Be Input Parameters
- #593 – Using Named Arguments
- #594 – When You’d Want to Use Named Arguments
- #597 – Returning an Array from a Method
- #608 – Instance Methods Can Use Static Data
- #632 – Partial Methods
- #633 – The Implementation of A Partial Method Is Optional
- #634 – Invoking Partial Methods That Have No Implementation
- #635 – Limitations on Partial Methods
- #636 – The Reason for Partial Methods
- #637 – A Delegate Can Refer to A Partial Method
- #638 – Defining and Using a Partial struct
- #674 – Can Overload If Parameters Differ Only by ref Modifier
- #695 – Static Methods Can Access Static Members
- #772 – Initializing an Array as Part of a Method Call
- #774 – Passing an Array as an out Parameter
- #802 – A Method Might Have No Parameters
- #807 – Defining and Using an Extension Method
- #808 – Adding Parameters to an Extension Method
- #809 – Extension Method Signatures Shouldn’t Match Class Methods
- #810 – Where Extension Methods Came From
- #811 – Extension Methods Can Only Access Public Members of Class
- #812 – Defining an Extension Method for a Value Type
- #813 – Defining an Extension Method for an Enumerated Type
- #814 – Parameters vs. Arguments
- #815 – Named vs. Positional Arguments
- #816 – Named Argument and Optional Parameter Combinations
- #1,038 – Type Parameter Constraints on Generic Methods
- #1,136 – Overloading a Generic Method
- #1,165 – Lambda Expression Basics
- #1,166 – Lambda Expression Syntax
- #1,167 – Passing a Lambda Expression to a Method
- #1,168 – Using a Lambda Expression as an Event Handler
- #1,169 – Lambdas Supersede Anonymous Methods
- #1,170 – You Can’t Unsubscribe from an Event Using a Lambda Expression
- #1,171 – Lambda Expression Internals
- #1,172 – Lambda Expressions Often Used with Func and Action
- #1,173 – Lambda Expression Can Be Just an Expression
- #1,174 – Assigning a Lambda Expression to an Expression Tree
- #1,175 – An Example of an Expression Tree
- #1,176 – How an Expression Tree is Stored in Memory
- #1,177 – Lambda Expressions Can Reference Variables Declared Outside of Expression
- #1,178 – Captured Variables Are Evaluted when a Delegate Is Invoked
- #1,179 – Captured Variable’s Lifetime Matches Delegate
- #1,180 – Lambda Expressions Can Modify Captured Variables
- #1,181 – Instantiating an Object within a Lambda Expression
- #1,182 – Capturing a for Loop Variable in a Lambda Expression
- #1,183 – How to Correctly Capture a for Loop Variable in a Lambda Expression
- #1,186 – Capturing a foreach Iteration Variable in a Lambda Expression
- #1,187 – Using a Lambda Expression When Adding to an Invocation List
- #1,188 – Lambda Expression Can Capture Instance Data
- #1,189 – Lambda Expression Can Capture Static Data
- #1,190 – A Lambda Expression Can Be Recursive
- #1,191 – Lambda Can’t Capture ref or out Parameters
Miscellaneous
- #453 – Use Reflection to Get a List of Interfaces that a Class Implements
- #480 – Pre-Processing Directives
- #725 – Dumping Out a List of Types in an Assembly
- #726 – Listing all Types within a Namespace
- #727 – Get a List of All Namespaces in an Assembly
- #728 – Dumping Out All Types in the .NET Framework
- #729 – Dumping Out All Types in .NET Framework, part II
- #731 – Getting Information About the Members of a Class
- #743 – ASCII Art Generator
- #745 – Use ReSharper to Increase Your Productivity in Visual Studio
- #748 – Use GhostDoc Tool to Document Your Code
- #749 – Example of Some C# Design Patterns
- #750 – Use xUnit.net for Unit Testing
- #757 – Books on Object-Oriented Programming
- #942 – The Case for Lazy Instantiation
- #943 – Lazy Instantiation, Solution #1
- #944 – Lazy Instantiation, Solution #2
- #945 – Lazy Instantiation, an Easier Solution
- #946 – Specifying Whether Lazy Instantiated Object Should Be Thread-Safe
- #947 – Specifying Lazy Instantiation Using a Lambda Expression
- #984 – The Birthday Problem
- #1,101 – Mathematical Constants
- #1,202 – C# 6.0 – Null-Conditional Operator
- #1,203 – C# 6.0 – Using the Null-Conditional with Value Types
- #1,204 – C# 6.0 – Using Null-Conditional with Indexer
- #1,205 – C# 6.0 – Using the Null-Conditional when Invoking a Delegate
- #1,206 – C# 6.0 – Auto-Property Initializers
- #1,207 – C# 6.0 – Auto-Property Initializers for Read-Only Properties
- #1,208 – C# 6.0 – Auto-Property Initializers Can Be Any Expression
- #1,209 – C# 6.0 – Using the nameof Operator
- #1,210 – C# 6.0 – Primary Constructors
- #1,211 – C# 6.0 – Adding Implementation for a Primary Constructor
- #1,212 – List of Features Shipping in C# 6.0
- #1,214 – C# 6.0 – using Directive with Static Class
- #1,215 – C# 6.0 – New Syntax for Dictionary Initializers
- #1,216 – C# 6.0 – Initializing Read-Only Auto-Properties from Constructors
- #1,217 – C# 6.0 – Using Lambda Expressions for Function Members
- #1,218 – C# 6.0 – Using Lambdas for Getter-Only Auto-Properties
- #1,219 – C# 6.0 – Filtering Exceptions
Operators
- #396 – Operators as Class Members
- #397 – Defining an Operator
- #398 – Overloadable Operators
- #399 – Overloading Unary Operators
- #400 – Overloading Binary Operators
- #405 – Equals Method for Equivalence, == Operator for Identity
- #408 – Overloading the == Operator for a Reference Type
- #409 – Example of Overloading the == Operator
- #410 – Overloading the == Operator for a Value Type
- #412 – Guidelines when Overloading == Operator for a Value Type
- #414 – Equivalence Can Be Based on a Subset of Fields
- #415 – Be Careful When Checking Floating Point Numbers for Equality
- #416 – Use an Epsilon to Compare Two Floating Point Numbers
- #419 – Override Relational Operators When You Implement IComparable
- #575 – Using the is Operator to Check the Type of a Reference-Typed Object
- #576 – Using the is Operator with Value Typed Objects
- #577 – Using the is Operator to Check for an Unboxing Conversion
- #578 – Using the as Operator to Do Type Conversions
- #579 – Typical Pattern for Using as Operator
- #580 – as Operator Can Generate Compile-Time Errors
- #592 – Optional Parameters in Indexers
- #1,071 – The Unary Minus Operator
- #1,072 – How the Unary Minus Operator Can Fail
- #1,073 – Arithmetic Binary Operators are Left-Associative
- #1,074 – Use Parentheses in Expressions to Make Code More Readable
- #1,075 – Operator Precedence Doesn’t Affect Operand Evaluation Order
- #1,100 – Increment and Decrement Operators Are Not Thread-Safe
- #1,106 – Using the Logical Exclusive OR Operator
- #1,107 – The Bitwise AND Operator
- #1,108 – The Bitwise OR Operator
- #1,109 – The Bitwise NOT Operator
- #1,110 – The Bitwise Exclusive OR Operator
- #1,114 – Don’t Use Shift Operators to Do Multiplication
- #1,200 – Logical Operators vs. Conditional Logical Operators
- #1,201 – Writing Conditional Logical Operators as Conditionals
Patterns
- #785 – The Singleton Pattern
- #786 – A Lazier Singleton Pattern
- #792 – Being Notified When an Object’s Properties Change, Part I
- #793 – Being Notified When an Object’s Properties Change, Part II
- #794 – A Better INotifyPropertyChanged Implementation
- #821 – The Factory Pattern
- #822 – Embed a Factory Class Inside Its Related Class
- #823 – A Nested Factory Class Implemented as a Singleton
- #948 – Using Generic Lazy Class to Implement the Singleton Pattern
Security
- #976 – Security Issues when Storing Confidential Data in Strings
- #977 – Security Issues with Managed Strings
- #978 – Use a SecureString Object to Store Confidential Text Data
- #979 – Store Confidential Data Only Within SecureString Instances
- #980 – Getting Data Out of a SecureString
Statements
- #157 – Iterating Using the while Loop
- #158 – A while Loop Expression Is Evaluated Before Executing the Loop
- #159 – A while Loop Might Execute Forever
- #160 – A while Loop Can Exit on break, goto, return or throw Statements
- #161 – Use continue to Jump to Next Iteration of while Loop
- #162 – do/while Loop Executes at Least Once
- #163 – Iterating Using the for Loop
- #164 – for Loop Clauses Can Contain Lists of Statements
- #165 – Any Clause of the for Loop May Be Left Empty
- #166 – Using the for Statement to Create an Infinite Loop
- #167 – Use continue to Jump to Next Iteration of for Loop
- #168 – Use if Statement to Conditionally Execute a Block of Code
- #169 – The if Statement Must Always Include a Boolean Expression
- #170 – The else Portion of an if Statement
- #171 – if/else Statement Can Have One or More Statements in Body
- #172 – Nested if Statements
- #173 – The switch Statement
- #174 – Multiple Case Statements in switch Statement Can Share Code
- #175 – The default Clause of a switch Statement
- #176 – Switch Statement Doesn’t Fall Through from Case to Case
- #177 – Using goto in a switch Statement
- #178 – Throwing an Exception from a switch Statement
- #986 – Using goto to Jump to a Label
- #1,115 – Iterating Through a Collection Using the foreach Statement
- #1,119 – Scope of Iteration Variable Is Limited to Body of foreach
- #1,120 – The Iteration Variable in a foreach Loop Is Read-Only
- #1,121 – Modifying Elements in a Collection Using foreach
- #1,122 – It’s Okay to Capture Variables within a foreach Loop
- #1,123 – Using foreach to Iterate on a Multidimensional Array
- #1,124 – Iterate through Jagged Array with Nested foreach
- #1,125 – Use of break and continue Statements
- #1,126 – Rewriting a Loop to Avoid continue Statement
Strings
- #14 – Composite Format Strings in C#
- #15 – Using Long Lists of Format Items in Composite Format Strings
- #16 – Use an Array of Objects for a Composite Format String
- #17 – Methods that Support Composite Formatting
- #25 – String Literals
- #33 – The string Type
- #60 – Using Parse to Convert from String to Numeric Types
- #61- Formatting and Parsing Strings for Non-Default Cultures
- #62 – String Concatenation
- #63 – Use StringBuilder for More Efficient String Concatenation
- #64 – Escape Sequences in String Literals
- #65 – Verbatim String Literals
- #66 – Including Quotation Marks in Strings
- #68 – String Equality
- #69 – Strings are Immutable
- #70 – The StringBuilder Class
- #71 – StringBuilder Capacity
- #95 – ToString() Called Automatically When Doing String Concatenation
- #96 – Comparing String Values
- #97 – String Comparisons Using Other Cultures
- #98 – Using An Indexer to Get A Specific Character in A String
- #99 – Use StringInfo to Get Specific Characters From A UTF32 String
- #100 – Using IndexOf to Search for Characters Within A String
- #101 – Use Contains() to Discover If A String Contains Other Strings
- #102 – Use Substring() to Extract Substrings From A String
- #103 – Inserting and Removing Substrings
- #104 – Functions to Trim Leading and Trailing Characters From A String
- #105 – Chaining String Functions Together
- #106 – Using String.Split to Parse A String Into Substrings
- #392 – Reversing a String Using the Reverse Method
- #422 – How ReferenceEquals Behaves When Comparing Strings
- #478 – Verbatim String Literals Can Span Multiple Lines
- #479 – Identical String Literals Are Stored in the Same Object
- #773 – Reversing a String that Contains Unicode Characters Expressed as Surrogate Pairs
- #970 – Checking for Valid Characters in a String
- #1,003 – Accessing Underlying Bytes in a String for Different Encodings
- #1,004 – Converting a String to Uppercase or Lowercase
- #1,005 – Replacing a Substring with a New Substring
- #1,006 – Getting the Length of a String
- #1,007 – Getting Length of String that Contains Surrogate Pairs
- #1,008 – What Happens When You Forget That Strings Are Immutable
- #1,009 – A String Can Be Null or Empty
- #1,010 – Checking to See Whether a String is Null or Empty
- #1,011 – TryParse Indicates Whether a Parse Operation Will Succeed
- #1,116 – Iterating Through a String Using the foreach Statement
Visual Studio
- #13 – Specify Command Line Arguments in Visual Studio 2010
- #113 – Conditionally Compiling Code Base on Symbols
- #114 – Creating a New Build Configuration
- #115 – Using #if, #else, #endif
- #116 – Use #region Directive to Create Code Regions
- #300 – Use XML Documentation to Inform Intellisense
- #301 – Using XML Documentation at the Class Level
- #302 – Generating an XML Documentation File
- #439 – Use Visual Studio to Implement an Interface
- #452 – Object Browser Shows You the Interfaces that a Class Implements
- #474 – You Can Include Unicode Characters in Your Source Code
- #481 – Projects and Solutions in Visual Studio
- #482 – Basic Project Types in Visual Studio
- #483 – Adding a new Project to an Existing Solution
- #484 – Add a Project Reference to Use a Type from Another Project
- #487 – Build Configurations Allow Saving Sets of Project Properties
- #488 – Build Platforms Allow Project Properties to Target a Platform
- #489 – Debug and Release Configurations Are Created Automatically
- #490 – Using the DEBUG Conditional Compilation Symbol
- #492 – Define Your Own Conditional Compilation Symbol
- #493 – Project Properties Are Specific to Build Configuration and Platform
- #494 – Selecting a Solution-Level Build Configuration and Platform
- #495 – Viewing Solution Configurations with the Configuration Manager
- #496 – Editing Solution Configurations with the Configuration Manager
- #497 – Creating a New Build Configuration in a Project
- #498 – Creating a New Solution Configuration
- #528 – Types Are Organized by Namespace in the Object Browser
- #591 – How Optional Parameters Look with Intellisense
- #595 – Intellisense Shows Method Overloads
- #663 – Visual Studio Debugger Will Call Your Object’s ToString Method
- #691 – Use the this Keyword to Trigger Intellisense
- #746 – Get a Free Copy of Visual Studio 2012
- #747 – Turning Off All Caps Menus in Visual Studio 2012
- #755 – Viewing Class Members Directly in the Solution Explorer
- #756 – Viewing a Class Diagram in Visual Studio 2012
- #758 – Cleaning Up using Directives in a File
- #759 – Creating a New Type from a Class Diagram
- #760 – Adding New Class Members from a Class Diagram
- #761 – Create or Modify Type Members Using the Class Details Window
- #762 – Creating a Class Diagram Containing Types in the .NET Framework
- #763 – Fixing a Class Diagram that Cannot Find Types
- #764 – Expanding All Classes in a Class Diagram
- #765 – Adding Base or Derived Classes to a Class Diagram
- #766 – Adding an Interface to a Class Diagram
- #770 – Use Intellisense to Get List of Methods to Override
- #848 – Viewing the Call Stack in Visual Studio
- #849 – Using the Call Stack in Visual Studio to Navigate within Your Code
- #1,184 – Managing using Directives, part I
- #1,185 – Managing using Directives, part II
- #1,213 – Visual Studio 2014 – Unused using Statements Greyed Out
Pingback: Sean Sexton - Ten Minutes With The Man Behind 2000 Things For C# Blog
Your Articles are Perferct.. Thx
Pingback: 2000 things – Vikram Shetty
I would like to say… Excellent.
Your web site is extremely useful to beginners.
Thanks a lot
Not just beginners, good concise info on more advanced topics too
Thank you so much, Sean Sexton, your articles are of great help.
Pingback: 2000条你应知的WPF小姿势 基础篇<51-56 依赖属性> – 小九的学堂 | 查问题
Is there any way to list your posts in number order?
Sorry Dominic, there’s no easy way to do this.
Great Thanks from china..
Pingback: How To Fix Error 1209 Sharp Errors - Windows Vista, Windows 7 & 8
Thanks a ton
by reading your articles i can say “Excellent”
I’m preparing for the MS Exam 70-483 – Programming in C# and find your posts very helpful for it.
Great, glad to hear it!
Pingback: 2,000 Things You Should Know About C# | Michael's Excerpts
Hi Sean,
Thanks for sharing valuable knowledge. I am regularly reading post but can you please write on or emphasize on Memory section because in using statement, try catch finally statement and in thread process i failed those to answer the question.
Please write more on Memory section.
Thank you very Much Sir!
Can you share any knowledge or information on ADO.Net like the way you have presented other concepts in C#
Hi James,
I’m glad that you like the C# information. Sadly, I don’t have bandwidth right now to talk about data access technologies or databases. I would strongly recommend reading up on Entity Framework, though. It’s a great data access technology. Just search for Julie Lerman and you’ll find everything you need to know.
Sean,
Is there a way you can share full set of code of the examples worked in these tutorials. For example, Doglibrary which includes all code in files Dog.cs,DogUtilities.cs, Ibark.cs etc. I know its wrong to ask after such a wonderful effort by you, but am finding difficult in mapping things w.r.t code if I taken a random question to work with as am a beginner-inetrmediate to learn this technology.Thank you.
Hi James, unfortunately all of the code that I have is already present in the posts. In some cases, if I’ve talked about a particular chunk of code, later posts will use that code without re-displaying it. In other cases, I omit code if I feel that it’s boilerplate or very simple code that you could throw together yourself.
That’s ok. I can understand.
One quick question. With the code you have provided in your tutorial(#858,#859), How do you
hit (I mean a test scenario to replicate) the “Catch” block for printing the user defined Exception messages like “I do not wish to bark at this time” in #858 and “Volume of 11 is too loud. Max volume is 10” in #859(I know if pass 11 as parameter to Bark method, the below message might print if an exception occurs). Where will these messages be placed in code and how to hit at a catch block to print these messages for my Test purpose.Thank you.
James, the exception handler (catch block) will be hit if an exception was thrown from any of the code called from within the try block. In post #858, we’re creating a new Dog object and called its Bark method. So if there is code that throws an exception in either the constructor or Bark method, or any code that those methods call, you’ll hit the code in the catch block.
Hello Sean,
Your website is really impressive, I love this idea and the way you wrote these posts.
I will read these 1219 posts, I did a planning for that so it should take around 3 months (10 daily => 5x morning and 5x night and weekends as well) to finish.
In 3 months I will come back here to give you my feedback 🙂
Thanks
Steve
Hello Sean,
I read all these posts and I have learned so many things, thanks a lot !
The way you wrote makes it easy to read in public transport (bus, subway, train, etc.).
Thanks
Steve
Thanks Steve. Glad to hear it!