100 Must Know Tips to Write Better C#

100 Must Know Tips to Write Better C#

22.384 Lượt nghe
100 Must Know Tips to Write Better C#
Get 30% off everything on Dometrain: https://dometrain.com/courses/?ref=nick-chapsas&promo=youtube&coupon_code=SUMMER30 Subscribe to my weekly newsletter: https://nickchapsas.com Hello, everybody. I'm Nick, and in this video, I will show you 100 .NET Tips that I have already taught in the form of YouTube Shorts, for everyone to enjoy in a single long video. Workshops: https://bit.ly/nickworkshops Don't forget to comment, like and subscribe :) Timestamps 00:00 Intro 00:35 Tip 1: Array.Empty 01:23 Tip 2: Are you rethrowing exceptions correctly 02:15 Tip 3: Make your async code thread safe 03:11 Tip 4: Linq performance Trap 04:01 Tip 5: Write C# in your terminal 04:41 Tip 6: Fastest way to work with lists 05:22 Tip 7: Biggest Lie about the .Net Logger 06:07 Tip 8: Empty Types in C#9 06:38 Tip 9: ToList vs ToArray 07:19 Tip 10: Assembly Markers are Awesome 08:00 Tip 11: StringSyntax Attribute 08:30 Tip 12: C#12 Primary Constructors 09:04 Tip 13: UUIDv7 and why it's better than UUIDv4 09:47 Tip 14: The smallest valid C# program (and what it means) 10:16 Tip 15: CancellationToken best practices 10:53 Tip 16: Collection initialisers and new syntax 11:17 Tip 17: Checking your .NET project with `dotnet-outdated` 11:48 Tip 18: Generating nonsense with a waffle generator 12:30 Tip 19: Run and UseMap for one-line top-level logic 12:55 Tip 20: The Big List of Naughty Strings in C# 13:30 Tip 21: Parsing with interpolated strings 14:12 Tip 22: Using type aliases for `Any T `-like behavior 14:44 Tip 23: DateTimeOffset: why you probably want it 15:25 Tip 24: Architecture testing with NetArchTest 15:59 Tip 25: Alternatives to FluentAssertions 16:38 Tip 26: Exporting C# types as JSON Schema 17:08 Tip 27: For/await loops over IAsyncEnumerable 17:39 Tip 28: .NET Retest for test impact analysis 18:11 Tip 29: The `params` keyword demystified 18:36 Tip 30: Why `Monitor.Enter` can troll you 19:14 Tip 31: Private fields and the underscore naming convention 19:43 Tip 32: HttpClientFactory explained in 2 minutes 20:20 Tip 33: Snapshot testing in C# with Verify 20:54 Tip 34: Intro to Refit: type-safe REST clients 21:22 Tip 35: Avoiding thread limits with SemaphoreSlim 22:03 Tip 36: ULIDs: lexicographically sortable unique IDs 22:39 Tip 37: Better parallelisation with Task.WhenAll 23:18 Tip 38: Using `IServiceScopeFactory` for scoped resolution 23:56 Tip 39: Issues with primary constructors in large projects 24:34 Tip 40: Using UnitsNet for unit-safe calculations 25:02 Tip 41: Detecting missing `services.ValidateScopes()` 25:31 Tip 42: Null-coalescing assignment `??=` in depth 26:02 Tip 43: Initialising dictionaries: concise methods 26:44 Tip 44: class vs record vs primary constructor 27:18 Tip 45: ref structs: when and why 27:58 Tip 46: in parameters explained 28:35 Tip 47: Deferred execution with LINQ: a quick demo 29:06 Tip 48: `stackalloc` for fast allocation on the stack 29:50 Tip 49: Built-in delegates like Action, Func, Predicate 30:42 Tip 50: Base class method overrides and visibility 31:28 Tip 51: Renting arrays with ArrayPool.Shared 32:10 Tip 52: `async void`: why it’s dangerous 32:40 Tip 53: The null-forgiving operator `!` in C# 33:14 Tip 54: `using` keyword corner cases 33:58 Tip 55: Object cloning with the `with` keyword 34:36 Tip 56: Extension methods best practices 35:13 Tip 57: Collection expressions in C# 12 35:41 Tip 58: Passing `Span T` with `params`-like syntax 36:05 Tip 59: Target-typed `new()` and when it helps 36:24 Tip 60: Top-level statements cleaned up 36:55 Tip 61: Pattern matching with logical operators 37:21 Tip 62: `nameof` usage patterns 37:45 Tip 63: Writing custom deconstructors 38:07 Tip 64: Lambda attributes and metadata 38:31 Tip 65: Advanced pattern matching techniques 38:54 Tip 66: `ThrowIfNull` and guard clauses 39:22 Tip 67: Expression-bodied constructors 39:45 Tip 68: Working with `ValueTuple` 40:14 Tip 69: Tip 69 40:50 Tip 70: `ref` vs `in` parameters in method signatures 41:24 Tip 71: Comparing tuples for equality 41:45 Tip 72: Using CallerMemberName/LineNumber/FilePath attributes 42:23 Tip 73: Lesser known attribute tricks in .NET 42:57 Tip 74: Should you use `var`? 43:34 Tip 75: The good and bad of `dynamic` 44:24 Tip 76: Exceptional exception handling techniques 44:55 Tip 77: Async void in test methods 45:26 Tip 78: #region is (probably) a code smell 46:06 Tip 79: Proper use of the `[Obsolete]` attribute 46:35 Tip 80: The future of .NET (v2) 47:02 Tip 81: Global usings in .NET 6+ 47:21 Tip 82: `nameof` again? Yes, but different context 47:44 Tip 83: `InternalsVisibleTo` and its pitfalls 48:11 Tip 84: User-filtered exception handling 48:27 Tip 85: New `when not null` pattern 49:01 Tip 86: What `scoped` really means 49:27 Tip 87: Finalizers in modern .NET 49:57 Rest: Character length exceeded Social Media: Follow me on GitHub: https://github.com/Elfocrash Follow me on Twitter: https://twitter.com/nickchapsas Connect on LinkedIn: https://www.linkedin.com/in/nick-chapsas #csharp #dotnet