Nov 23 2024
public void PrintNumbers(params List<int> numbers) { foreach (var number in numbers) { Console.WriteLine(number); } } // Usage PrintNumbers(new List<int> { 1, 2, 3 });
public void PrintNumbers(params int[] numbers) { foreach (var number in numbers) { Console.WriteLine(number); } } // Usage PrintNumbers(1, 2, 3); // Could only use arrays directly.
Lock myLock = new Lock(); using (myLock.EnterScope()) { // Critical section Console.WriteLine("Thread-safe code here."); }
private static readonly object _lock = new object(); void ThreadSafeMethod() { lock (_lock) { // Critical section Console.WriteLine("Thread-safe code here."); } }
Console.WriteLine("\e[1mThis is bold text\e[0m");
Console.WriteLine("\x1b[1mThis is bold text\x1b[0m");
var numbers = new int[5] { 1, 2, 3, 4, 5 }; var initializer = new List<int> { [^1] = 10 }; // Sets the last element to 10
var numbers = new int[5] { 1, 2, 3, 4, 5 }; var initializer = new List<int> { 1, 2, 3, 4, 5 }; initializer[initializer.Count - 1] = 10; // Manually set the last element.
public async Task ProcessDataAsync() { Span<byte> buffer = stackalloc byte[1024]; // Unsafe context await Task.Delay(1000); }
void ProcessData() { Span<byte> buffer = stackalloc byte[1024]; // Unsafe context } // Asynchronous wrapper public async Task ProcessDataAsync() { await Task.Run(() => ProcessData()); }
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.