C Sharp
- Getting Started with C# & .NET in VS Code (Official Beginner Guide) - James
YouTube Video
Click to view this content.
- Building a Database Engine in C# & .NET - Khalid@JetBrains
YouTube Video
Click to view this content.
- WPF, Plugins, Dependency Injection - Live Coding in C# - Nick Cosentino
YouTube Video
Click to view this content.
- C# Array and List Fastest Loop in 2024 - NDepend Blogblog.ndepend.com C# Array and List Fastest Loop in 2024 - NDepend Blog
What is the most efficient loop in c#? Let's find out by investigating looping over both array and list in this blog post.
- StringBuilders magic for very large stringssteven-giesel.com StringBuilders magic for very large strings
The StringBuilder class is used to create mutable sequences of characters. Strings are immutable, so if you need to perform multiple operations on a string, it is better to use a StringBuilder instead of a string. This is especially useful when you need to concatenate a large number of strings. But ...
- ONLY 0.7% Of The Memory Allocations When Downloading In C# - Nick Cosentino
YouTube Video
Click to view this content.
- Chris "Woody" Woodruff - Networking programming RSS feed announcementmastodon.social Chris "Woody" Woodruff (@cwoodruff@mastodon.social)
Stay updated with the latest network programming knowledge in #CSharp and #DotNet! π Check out the new RSS feed for "Beyond Boundaries - Networking Programming with C# 12 and .NET 8" for tips, updates, and expert insights. Follow along at https://rssviewer.app/https%3A%2F%2Frss.app%2Ffeeds%2FvKGL7...
- Thoughts about primary constructors: 3 pros and 5 cons - Andrew Lockandrewlock.net Thoughts about primary constructors: 3 pros and 5 cons
In this post I describe some of the ways I like to use primary constructors and some of the things I don't like about them
- .NET Announcements & Updates from Microsoft Build 2024 - .NET Blogdevblogs.microsoft.com .NET Announcements & Updates from Microsoft Build 2024 - .NET Blog
Our latest updates and announcements from Microsoft Build including .NET Aspire, .NET 9 Preview 4, C# 13, Blazor, .NET MAUI, and more!
- Refactor your code with C# collection expressions - .NET Blogdevblogs.microsoft.com Refactor your code with C# collection expressions - .NET Blog
Explore various C# 12 refactoring scenarios for a variety of target types using collection expressions and collection initializers.
- Beyond Boundaries - Networking Programming with C# 12 and .NET 8 Book Homecsharp-networking.com Beyond Boundaries - Networking Programming with C# 12 and .NET 8 Book Home
Have questions or feedback about the book? My email is cwoodruff@live.com.
- C# workbook recommendations?
Hi all. I've been wanting to get into programming for a while now, specifically C#. However, I am not good at self-study or self-guided learning. Are there any good textbooks/workbooks that you'd recommend to learners of C# as a first programming language? I have some experience with coding, but not much more than simple command-line calculators (due to aforementioned lack of self-teaching skills).
To clarify, I'm looking for a straightforward textbook where I could read a chapter and do the associated "exercises" (for lack of a better word)
- Opinions needed: Best way to develop NuGet packages
My favorite way to develop applications is microservices, or at least smaller services that can separate concerns a little bit. In our current application, there is an API we've created with an OAS document and an auto-generated .NET SDK based on the document. We then have a web console that makes calls to the backend API using the SDK and, ideally, customers would also use the SDK.
So my question to everyone is: what is the best "flow" to develop a NuGet package?
Currently, we have pipelines which publish the NuGet package of the SDK to our internal NuGet repository on every commit within a merge request. We have a manually incrementing semver with an additional build number tacked on (for example
1.2.3+abc123
).Now this works pretty well, but we often run into problems where a tester's NuGet doesn't pull down the latest version based on the build number if it detects it has the proper semver number. For example, if we create
1.2.3+abc456
NuGet won't pull down this version as long as it has the original1.2.3+abc123
in its.nuget/packages
directory. Testers and developers have to manually delete the version from the packages directory and do a fresh restore.So, is there a better way to do build numbers? Or should I be deleting the NuGet package from the private repository every time (doesn't sound ideal...)?
The other part of this question is what is the best way to develop and test NuGet packages locally?
My current flow is a PowerShell script which will create the new
.nupkg
file, publish it to a local/filesystem NuGet directory with some random semver number (i.e.,9.9.9
), update the.csproj
with the version (temporarily), and then do a freshdotnet restore
on the target project. However, this can be cumbersome and feels like something that should be built into thedotnet
command. Am I missing something, or is this really the best way to develop locally? - Fastest Way to Get the First N Characters of a String in C# - Code Mazecode-maze.com Fastest Way to Get the First N Characters of a String in C# - Code Maze
In this article, we will perform benchmark tests to determine the fastest way to get the first N characters of a string in C#.
- How to Use StringPool to Reduce String Allocations in C# - Code Mazecode-maze.com How to Use StringPool to Reduce String Allocations in C# - Code Maze
This article explores how to use StringPool to reduce string allocations in C#, including sample code and a benchmark section.
- async void Methods In C# β The Dangers That You Need to Knowwww.devleader.ca async void Methods In C# β The Dangers That You Need to Know
Learn why async void methods in C# can be dangerous with clear code examples. A perfect for beginner software engineers wanting to understand the risks.
- How to Implement the Strategy Pattern in C# for Improved Code Flexibilitywww.devleader.ca How to Implement the Strategy Pattern in C# for Improved Code Flexibility
Learn how the Strategy Pattern in C# provides flexibility! Let's explore an example of the strategy pattern in C# along with the pros and cons of using it!
- Async Event Handlers in C#: What You Need to Knowwww.devleader.ca Async Event Handlers in C#: What You Need to Know
Learn how to safely use async event handlers in C#. Understand the dangers and discover best practices for managing async event handlers in your C# code.
- Comparing Performance of the switch and if-else Statements in C#code-maze.com Comparing Performance of the switch and if-else Statements in C#
In this article, we delve into the performance nuances of switch and if-else statements in C#, two pivotal control flow mechanisms.
- Choosing Between Class and Struct - Framework Design Guidelineslearn.microsoft.com Choosing Between Class and Struct - Framework Design Guidelines
Learn how to decide whether to design a type as a class, or to design a type as a struct. Understand how reference types and value types differ in .NET.
- Farewell to the .NET Foundation Β· AvaloniaUI Avalonia Β· Discussion #14666github.com Farewell to the .NET Foundation Β· AvaloniaUI Avalonia Β· Discussion #14666
In April 2020, Avalonia proudly joined the .NET Foundation, marking a significant milestone in our journey. Our joining the Foundation was a moment of great optimism, as we hoped to contribute to a...
Twitter Link I personally like Avalonia and I hope this decision is for the best. But at the same time I don't know the benefits or disadvantages of being part of the .Net Foundation.
- Switch statement fallthrough in C#?stackoverflow.com Switch statement fallthrough in C#?
Switch statement fallthrough is one of my personal major reasons for loving switch vs. if/else if constructs. An example is in order here: static string NumberToWords(int number) { string[] nu...
- Build Levels.fyi in DotNet! - How To Use Google Sheets API in C#
YouTube Video
Click to view this content.
cross-posted from: https://programming.dev/post/10028855
> Build Levels.fyi in DotNet! - How To Use Google Sheets API in C#
- MAUI 8.06 Windows Flyout "Element is already the child of another element"
cross-posted from: https://programming.dev/post/9780587
> In MAUI 8.03 we had the Flyout bug where the NavigationPage Title wouldn't update from the first page you had been on. In MAUI 8.06 that bug has been fixed but has introduced a new one on Windows (sigh). > > Starting on Page1 I can use the Flyout to switch to Page2. Then, on Windows, if I use Flyout to switch back to already-existing Page1 it crashes with... > >
> System.Runtime.InteropServices.COMException (0x800F1000): No installed components were detected. > > Element is already the child of another element >
> > It works on Android, and it works if you are creating a new page each time, it just doesn't work on Windows to switch back to an already-created page (which defeats the whole purpose of having a Flyout menu - switch between 2 pages without making a new one every time). > > 1. Does anyone know of a workaround to this? I can't find anything that relates to this in the context of a MAUI Flyout. > 2. Does anyone have a real simple Flyout template that could be used for the repro (to put in the issue I'm gonna need to create). The one I'm working on has a whole bunch of my own libraries in it, so I'm gonna need to tear them all out before I can use it to make a repro (and of course they don't provide a template, and their sample doesn't work due to different bugs - sigh). - Brisbane-based dotnet role
cross-posted from: https://programming.dev/post/9650331
> Just had this pop up in my Mastodon feed, if we have any Brisbane-based dotnet engineers in the job market here eigenmagic.net/@arichtman/111883866093603121
- Suggestions on a design pattern for logging in .NET?
Hello! I'm starting a personal project in .NET.
For a logging solution, I want to achieve something similar to what I have in a Python REST API I wrote a while back using the decorator pattern (example in the image).
In the example, the outter "log" function receives the logger I want to use, the decorator function receives a function and returns the decorated function ready to be called (this would be the decorator), and the wrapper function receives the same arguments as the function to be decorated (which is a generic (*args, **kwargs) ofc, because it's meant to decorate any function) and returns whatever the return type of the function is (so, Any). In lines 17 - 24 I just call the passed in "func" with the passed in arguments, but in between I wrap it in a try except block and log that the function with name
func.__name__
started or finished executing. In practice, using this decorator in Python looks like this:``` import logging from my.decorator.module import log
_logger = logging.getLogger(name)
@log(_logger) def my_func(arg1: Arg1Type, arg2: Arg2Type) -> ReturnType: ... ```
Ofc it's a lot simpler in Python, however I was wondering if it would be possible or even recommended to attempt something similar in C#. I wouldn't mind having to call the function and wrap it manually, something like this:
return RunWithLogs(MyFunction, arg1, arg2);
What I do want to avoid is manually writing the log statements inside the service's business logic, or having to write separate wrappers for each method I want to log. Would be nice to have one generic function or class that I can somehow plug-in to any method and have it log when the call starts and finishes.
Any suggestions? Thanks in advance.
- Output of Microsoft.Extensions.Logging in a MAUI app
cross-posted from: https://programming.dev/post/8419041
> I'm just trying out the built-in builder.Logging.AddDebug(); in a MAUI app, but don't see the output anywhere. From several blogs I expected to see the messages in the Visual Studio Debug output window, but they aren't appearing. > > Just using the stock-standard MAUI app, the only changes I have made are in App.cs as follows... >
csharp > using Microsoft.Extensions.Logging; > using Microsoft.Maui.Controls; > namespace BaseMAUIApp; > internal class App :Application > { > public App(ILogger<App> logger) { > logger.LogDebug("******************* Message from logger!"); > // rest of code... >
> > But I don't see my message anywhere. Is there something else I have to configure, or somewhere else I have to look? > - C# language snags Tiobe language of the year honorswww.infoworld.com C# language snags Tiobe language of the year honors
Microsoftβs object-oriented programming language for .NET development had the largest increase in popularity, gaining on Java, C++, C, and Python.
- My blog on how to create a MAUI UI in C#
cross-posted from: https://programming.dev/post/6722007
> I had cause to mention this to someone today, and thought I would share this here for anyone who may not have seen it before and would be interested in this info - Creating MAUI UI's in C#
- Is preloading/caching data before the actual method call an (anti)pattern?
Short explanation of the title: imagine you have a legacy mudball codebase in which most service methods are usually querying the database (through EF), modifying some data and then saving it in at the end of the method.
This code is hard to debug, impossible to write unit tests for and generally performs badly because developers often make unoptimized or redundant db hits in these methods.
What I've started doing is to often make all the data loads before the method call, put it in a generic cache class (it's mostly dictionaries internally), and then use that as a parameter or a member variable for the method - everything in the method then gets or saves the data to that cache, its not allowed to do db hits on its own anymore.
I can now also unit test this code as long as I manually fill the cache with test data beforehand. I just need to make sure that i actually preload everything in advance (which is not always possible) so I have it ready when I need it in the method.
Is this good practice? Is there a name for it, whether it's a pattern or an anti-pattern? I'm tempted to say that this is just a janky repository pattern but it seems different since it's more about how you time and cache data loads for that method individually, rather than overall implementation of data access across the app.
In either case, I'd like to learn either how to improve it, or how to replace it.
- .NET Architecture: Framework Design Guidelineslearn.microsoft.com Framework Design Guidelines
See framework design guidelines for designing libraries that extend and interact with .NET, to ensure API consistency and ease of use.
- GitHub - dotnet/roslynator: Roslynator is a set of code analysis tools for C#, powered by Roslyn.github.com GitHub - dotnet/roslynator: Roslynator is a set of code analysis tools for C#, powered by Roslyn.
Roslynator is a set of code analysis tools for C#, powered by Roslyn. - GitHub - dotnet/roslynator: Roslynator is a set of code analysis tools for C#, powered by Roslyn.
- Announcing C# 12devblogs.microsoft.com Announcing C# 12 - .NET Blog
Announcing the official release of C# 12, including collection expressions, primary constructors, and more!