c-sharp-code-examples icon indicating copy to clipboard operation
c-sharp-code-examples copied to clipboard

C# Code Examples / Snippets

C# Code Examples (mostly for myself)

A collection of code samples I have used C# and think they might be useful in the future.

Sample Categories

  • Abstract Class
  • Anonymous Types
  • Attributes and Conditionals
    • Debugger
      • DebuggerDisplay
      • DebuggerBrowsable
      • Conditional
      • #if - #define - #endif
    • Obsolete
      • Compiler Warning
      • Compiler Error
    • Conditional
  • Classes
    • Get current Class name
    • Get current Method Name
    • Constructor Chaining
    • Caller Info
  • Comparing
    • IEquatable<T> Additional links: Link
    • IEqualityComparer<T> Additional links: Link
  • Design Patterns
    • Creational Patterns
      • Singleton Pattern
      • Factory Method Pattern
      • Abstract Factory Pattern
    • Behavioral Patterns
      • Strategy Pattern
      • Observer Pattern
      • State Pattern
  • Dictionaries
  • Extension Methods
  • Garbage Collection
  • Implicit/Explicit Conversion operators
  • Interface
  • LINQ
    • Sum
    • Sum by Groups
    • Ordering (asc, desc)
    • Skipping
    • Take N elements
    • Select Samples with value between
  • Object Pool
  • Operator Overloading Additional links: Link
  • SOLID
    • Single Responsibility Principle
    • Inversion of Control
  • Syntactic Sugars
    • Auto Property
    • Auto Property with default value
    • Property getter/setter
    • String Interpolation
    • Using
    • Pattern Matching
  • Threading
    • BackgroundWorker
    • Thread
  • Timing
  • Tuple Deconstruction (requires System.ValueTuple); Additional links: Link

Useful Libraries

Universal

WPF Specific