Your API returns 10,000 rows and you're loading them into a `List<T>` before doing anything. Bold strategy. `IAsyncEnumerable<T>` lets you stream data asynchronously, processing each item as it arrives instead of waiting for the whole payload. It pairs with `await foreach` and it just works. --- await foreach (var tick in GetLiveTicker()) Console.WriteLine($"${tick.Symbol}: {tick.Price:F2}"); --- Shipped in C# 8 and .NET Core 3.0 back in 2019, it quietly solved the "why is my app eating 2GB of RAM" problem for a lot of teams. Run it, break it, learn it: https://lnkd.in/e5jMbUvr #dotnet #csharp #programming #asyncprogramming
Stream Async Data with IAsyncEnumerable in C#
More Relevant Posts
-
💻 Great .NET insights from Steven Giesel. This post dives into practical development concepts with clear explanations and real code examples—always a great resource for developers looking to sharpen their skills. 👉 https://lnkd.in/gp8vTSkr #dotnet #SoftwareDevelopment #Programming #DevCommunity
To view or add a comment, sign in
-
When a service accumulates 50+ command-line parameters, the limitations of static configuration become impossible to ignore. Servy v7.6 tackles this by replacing those parameters with an SQLite-based configuration system. This change isn’t just about storage — it enables runtime adjustments, built-in validation, and compatibility with tools like ORMs and migration scripts. Static configuration formats struggle under the weight of dynamic, versioned state — a problem SQLite solves with structure and persistence. This shift reflects a deeper principle: backend systems should evolve by adopting infrastructure that scales with complexity, not by adding layers of workarounds. I believe choosing the right tool for configuration is as critical as choosing the right architecture for the service itself. #CSharp #DotNet #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
𝗗𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝘆 𝗜𝗻𝗷𝗲𝗰𝘁𝗶𝗼𝗻 𝗶𝗻 𝗔𝗦𝗣.𝗡𝗘𝗧 𝗖𝗼𝗿𝗲: 𝗧𝗿𝗮𝗻𝘀𝗶𝗲𝗻𝘁 𝘃𝘀 𝗦𝗰𝗼𝗽𝗲𝗱 𝘃𝘀 𝗦𝗶𝗻𝗴𝗹𝗲𝘁𝗼𝗻 If you’re using Dependency Injection in ASP.NET Core, you’ve probably asked: • When should I use Transient? • Why is Scoped so common for DbContext? • When is Singleton actually safe? The answer lies in service lifetimes and choosing the wrong one can lead to: • memory leaks • threading issues • hard-to-debug bugs 𝗜’𝘃𝗲 𝗽𝘂𝘁 𝘁𝗼𝗴𝗲𝘁𝗵𝗲𝗿 𝗮 𝘀𝗶𝗺𝗽𝗹𝗲 𝘃𝗶𝘀𝘂𝗮𝗹 𝗲𝘅𝗽𝗹𝗮𝗻𝗮𝘁𝗶𝗼𝗻 𝘁𝗵𝗮𝘁 𝗯𝗿𝗲𝗮𝗸𝘀 𝗱𝗼𝘄𝗻: • what each lifetime really means • how long instances live • when to use each one in real projects 📌 𝗥𝗲𝗮𝗱 𝘁𝗵𝗲 𝗳𝘂𝗹𝗹 𝗮𝗿𝘁𝗶𝗰𝗹𝗲 𝗵𝗲𝗿𝗲: Understanding this early can save you hours of debugging later. Which service lifetime do you use the most in your projects Scoped, Singleton, or Transient? 𝗪𝗮𝗻𝘁 𝗺𝗼𝗿𝗲 𝗖# & 𝗔𝗦𝗣.𝗡𝗘𝗧 𝗖𝗼𝗿𝗲 𝘁𝗶𝗽𝘀 𝗹𝗶𝗸𝗲 𝘁𝗵𝗶𝘀? #dotnet #aspnetcore #csharp #dependencyinjection #softwaredevelopment #backend #programming
To view or add a comment, sign in
-
-
No try{} catch{} in C#? "Do or do not, there is no trying" — actually here Yoda was a bit wrong, because trying is the essential skill in C# and .NET. 💡 try { Here you execute some function (Ex: getting access to the db or API) } catch { But if you're smart enough you might be prepared for some problems. Two ways to play: — Lazy way is simply rethrow the exception to the other layer at now it's not your problem anymore — But if you expect something to go wrong you can try to catch specific exceptions (even custom ones) } finally { This part gets executed no mater what, so it's perfect place for example to close DB connection } What’s the weirdest exception you’ve ever had to catch?😳 #SoftwareEngineering #Programming #CodingTips
To view or add a comment, sign in
-
-
💡𝐂#/.𝐍𝐄𝐓 𝐀𝐬𝐲𝐧𝐜 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧 𝐓𝐢𝐩 🚀 💎𝐇𝐨𝐰 𝐚𝐧𝐝 𝐰𝐡𝐞𝐧 𝐭𝐨 𝐮𝐬𝐞 ‘𝐚𝐬𝐲𝐧𝐜’ 𝐚𝐧𝐝 ‘𝐚𝐰𝐚𝐢𝐭’ 💡 '𝐚𝐬𝐲𝐧𝐜' and '𝐚𝐰𝐚𝐢𝐭' keywords introduced in C# 5.0 were designed to make it easier to write asynchronous code, which can run in the background while other code is executing. The "async" keyword marks a method asynchronous, meaning it can be run in the background while another code executes. ⚡ When using 𝐚𝐬𝐲𝐧𝐜 and 𝐚𝐰𝐚𝐢𝐭 the compiler generates a state machine in the background. 🔥 Let's look at the other high-level details in the example; 🔸 𝐓𝐚𝐬𝐤<𝐢𝐧𝐭> 𝐥𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐓𝐚𝐬𝐤 = 𝐋𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐀𝐬𝐲𝐧𝐜(); starts executing 𝐋𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧. 🔸 Independent work is done on let's assume the Main Thread (Thread ID = 1) then 𝐚𝐰𝐚𝐢𝐭 𝐥𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐓𝐚𝐬𝐤 is reached. 🔸 Now, if the 𝐥𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐓𝐚𝐬𝐤 hasn't finished and it is still running, 𝐃𝐨𝐒𝐨𝐦𝐞𝐭𝐡𝐢𝐧𝐠𝐀𝐬𝐲𝐧𝐜() will return to its calling method, this the main thread doesn't get blocked. When the 𝐥𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐓𝐚𝐬𝐤 is done then a thread from the ThreadPool (can be any thread) will return to 𝐃𝐨𝐒𝐨𝐦𝐞𝐭𝐡𝐢𝐧𝐠𝐀𝐬𝐲𝐧𝐜() in its previous context and continue execution (in this case printing the result to the console). ✅ A second case would be that the 𝐥𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐓𝐚𝐬𝐤 has already finished its execution and the result is available. When reaching the 𝐚𝐰𝐚𝐢𝐭 𝐥𝐨𝐧𝐠𝐑𝐮𝐧𝐧𝐢𝐧𝐠𝐓𝐚𝐬𝐤 we already have the result so the code will continue executing on the very same thread. (in this case printing result to console). Of course this is not the case for in the example, where there's a 𝐓𝐚𝐬𝐤.𝐃𝐞𝐥𝐚𝐲(1000) involved. 🎯 𝐖𝐡𝐚𝐭 𝐝𝐨 𝐲𝐨𝐮 𝐭𝐡𝐢𝐧𝐤 𝐚𝐛𝐨𝐮𝐭 𝐚𝐬𝐲𝐧𝐜 𝐨𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬? #csharp #dotnet #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
🤯 C# 15 is introducing something developers have wanted for years — Union Types. Ever had a method that returns: • Success OR Error • Multiple possible results And ended up using object, exceptions, or extra classes? Union Types fix this 👇 👉 One type → multiple possibilities (type-safe) 👉 Cleaner pattern matching 👉 Safer refactoring I wrote a simple, story-based article explaining this with examples. 📖 Read here: https://lnkd.in/d7d3C3xF #csharp #dotnet #programming #softwaredevelopment #developers
To view or add a comment, sign in
-
.𝐍𝐄𝐓 𝟏𝟏 𝐢𝐬 𝐡𝐞𝐫𝐞 𝐢𝐧 𝐩𝐫𝐞𝐯𝐢𝐞𝐰. But the real question is not “what’s new”. It is: 👉 What actually matters for developers? After going through the updates, here is what stands out: • runtime improvements focused on performance • cleaner async with lower overhead • meaningful SDK and tooling updates • better System.Text.Json flexibility • new C# 15 features like union types At the same time, it is still a preview. Which means: • some features are incomplete • breaking changes can still happen • not ready for production The biggest takeaway for us: .NET 11 is not about big flashy features. It is about steady improvements that make development faster and cleaner. The article included a detailed breakdown covering: • runtime changes • library updates • SDK improvements • C# 15 features • what actually matters in real projects 👇 Link in the comments Are we planning to try .NET 11 early, or waiting for the stable release? #DotNet #CSharp #SoftwareEngineering #Programming #WebDevelopment
To view or add a comment, sign in
-
You don't have to write everything from scratch just because you're in a browser. dotnetfiddle.net lets you add real NuGet packages to your fiddle - Humanizer, Newtonsoft.Json, whatever you need. Just search, add, and run. No `.csproj`, no restore dance, no terminal. It shipped quietly years ago and somehow half the devs we know still don't use it. --- int bugs = 342; Console.WriteLine($"You have {bugs.ToWords()} bugs in your backlog."); Console.WriteLine($"That's been sitting there for {"day".ToQuantity(5)}."); Console.WriteLine("Status: " + "this_is_fine".Humanize()); --- Try it yourself (no setup required): https://lnkd.in/ezgMfRmj #dotnet #csharp #programming #nuget
To view or add a comment, sign in
-
-
You are still writing five-level if/else blocks to handle types and conditions. C# 8 brought switch expressions with property patterns, and they have been sitting there ever since, quietly judging you. Instead of checking properties one by one, you match against the whole shape of an object in one clean expression. --- var price = order switch { { Drink: "Espresso", ExtraShot: true } => 4.50, { Drink: "Latte", Size: <= 12 } => 3.75, { Size: >= 20 } => 6.00, _ => 2.50 }; --- Shipped in C# 8 (2019) and quietly upgraded every version since - relational patterns, nested patterns, you name it. Microsoft kept cooking on this one. Run it, break it, learn it: https://lnkd.in/eqSfeq5T #dotnet #csharp #programming #cleancode
To view or add a comment, sign in
-
-
🔥 Mastering HTTP POST in C# — 4 patterns you actually use Whether you're calling an API or building one, POST is everywhere. Here's a quick reference covering the patterns I reach for daily: ✅ HttpClient.PostAsJsonAsync — clean, built-in JSON serialization ✅ Minimal API MapPost — lightweight, production-ready ✅ Controller [HttpPost] — classic, structured, familiar ✅ Record DTOs + Data Annotations — validation in one line 💡 Quick wins to remember: → Always use IHttpClientFactory in production — raw HttpClient causes socket exhaustion → Return 201 Created with a Location header for new resources → [ApiController] handles ModelState validation automatically — no manual checks needed What's your go-to POST pattern? Drop it in the comments 👇 #dotnet #csharp #aspnetcore #webapi #softwaredevelopment #100daysofcode #programming
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development