Content that is all about programming and coding! Find examples of code often written in C# along with tutorials.

Beware of These Iterator and Collection Traps

This article is not set out to try and persuade you, the reader, that either using an iterator or materialized collection will universally solve your problems. Both iterator and materialized collection usage can be used to solve the scenarios that we'll be looking at, but both will come with a different set of pros and cons that we can further explore. The purpose of this article is to highlight scenarios based on real world experiences where either an iterator or materialized collection was being misunderstood, misused, and ultimately leading to a pile of headaches. As you read this article, if you find yourself saying "Well, sure, but they should have..." you're probably right. The problem is fundamentally not the usage of an iterator or the materialized collection, but not understanding how to consume them effectively. So I hope that when…

0 Comments

Iterators – An Elementary Perspective on How They Function

If you're newer to C# or programming in general, you may have used an iterator and not even realized it. Iterators can be a performant and effective tool that we have access to as .NET developers that allow us to traverse collections of data. Because one of the requirements of an iterator is that it must implement the IEnumerable interface, the results of an iterator can only be enumerated over. For example, you could use the results of an iterator in a foreach loop but you could not directly index into the iterator results (like you could an array) without some additional steps. Another requirement of iterators is that they use a special keyword called "yield" so that they can yield and return the individual elements that are to be provided to the caller of the iterator. In a nutshell,…

0 Comments

Everything You Wanted to Know About Multiline Strings

Working with strings is probably one of the earliest things we get to do as C# developers. In fact, if you consider that most of us start with the "Hello, World!" example, you're being exposed to the string type right away. But as you continue to use strings, you'll quickly find that you want to work with strings that span multiple lines and how we define multiline strings might be a tricky topic for beginners. No sweat! In this article, we'll look at some simple code examples that demonstrate how to define multiline strings. I'll also link over to GitHub where you can see this code committed and pushed up to a public repository. Finally, the last example contains a special bonus that I think you'll like (even if it's a slightly more advanced topic). Read until the end! What's…

0 Comments

Simple Data Types in C#: A Beginner’s Guide

As a C# developer, understanding the different simple data types in C# and when to use them is crucial for writing efficient and maintainable code. I've been trying to spend more time this year putting together some content aimed at really introductory level programming. There's plenty of resources available online, but I want to do my part to ensure I can help break down some of the barriers for people getting started on their programming journey. In this beginner's guide, we will look at the basics of the most commonly used simple data types in C#, including int, float, double, byte, char, bool, and string. We will also look at how these data types differ from each other and when to use them in your C# programming! Integer Data Types The most commonly used integer data types in C# are…

2 Comments

Tasks, BackgroundWorkers, and Threads – Simple Comparisons for Concurrency

(This article is intended to be a spiritual successor to this previous entry, and now includes Tasks!) Even if you're new to C#, you've probably come across at least one of Tasks, Threads, or BackgroundWorkers. With a bit of additional time, it's likely you've seen all three in your journey. They're all ways to run concurrent code in C# and each has its own set of pros and cons. In this article, we will explore how each one operates at a high level. It's worth noting that in most modern .NET applications and libraries you'll see things converging to Tasks. The Approach I've gone ahead and created a test application that you can find here. Because this is in source control, it's possible/likely that it will diverge from what we see in this article, so I just wanted to offer…

0 Comments

Pythonnet – A Simple Union of .NET Core and Python You’ll Love

Python is a powerful and versatile programming language that has become increasingly popular. For many, it's one of the very first programming languages they pick up when getting started. Some of the highest traffic posts on my blog many years after they were written look at using C# and Python together. Today we're going to explore how you can use Python from inside a C# .NET Core application with much more modern approaches than my original articles. Enter Pythonnet! Pythonnet Package & Getting Started We're going to be looking at Python for .NET in order to accomplish this goal. This library allows you to take advantage of Python installed on the running machine from within your .NET Core applications. You must configure it to point at the corresponding Python DLL that you'd like to use, and after a couple of…

1 Comment

The Hottest New Open Source OpenAI API for C#

If you have an internet connection then you have probably heard of ChatGPT from OpenAI by now. Odds are you might have even given it a whirl to see what it's all about. Personally, I know that I was quite skeptical at first but I've been blown away at how well it's able to converse about topics I ask it. I've even asked it to generate various scenarios for me and it will conclude by explaining why the different facets it chose were good choices. Incredible stuff. I'll be using this to help chip away at content for my role playing game. When it comes to using OpenAI effectively, I have a great deal to learn. It's all very new to me, especially with respect to how to structure prompts and get the most out of the interactions with such…

0 Comments

End of content

No more pages to load