Blog

Sometimes I worry about software development or I look for solutions to C# problems. If I come up with anything useful, I’ll post it here.

Blog Archive

Latest Posts

  • 0 is not equal to null. Definition and Use of the appropriate C# Types (h4-06)

    An input window for numerical input. Values between 0 and 7 are allowed. The mouse arrow is on the Cancel button.

    C# provides many data types. For example double, int and string. A string variable can have the value null. This null value has a few pitfalls to be aware of. Value types like int and double cannot be null, but you can define nullable value types. This post explains that in more detail with simple examples. At the end it will be explained how to use if and else statements to execute different parts of the program.

  • It is never to early to write Clean Code (h4-05)

    An image created with the Pen class of the Woopec library. On the left, a hexagonal figure drawn with green lines. On the right, a pentagonal figure drawn with blue lines.

    It is not enough for your code to do what it is supposed to do. You should strive to write clean code from the start. Even as a beginner, you can use code conventions and follow the DRY principle. This will help you write code that is easier to understand and extend. In this post, we use C# variables and loops to improve code that draws a hexagon.

  • Why is this simple C# Program not working? Fixing Compiler Errors and using the Visual Studio Debugger (h4-04)

    Image with Visual Studio compiler errors: CS1002 ; expected. CS1003 , expected. CS1022 Type or namespace definition, or end-of-file expected. CS7036 There is no argument given that corresponds to the required parameter. And more.

    You have written your first C# program and it compiles with errors? This is quite normal in the beginning. Don’t let that stop you from learning C#. Here I explain some of the most common errors and how to fix them. Your program runs, but doesn’t do what it’s supposed to do? This is also quite normal. With the Visual Studio Debugger, you can see step-by-step what your program is doing and quickly find out what is wrong.

  • Draw a filled hexagon using simple C# commands (h4-03)

    The previous post showed how to write your first C# program. Now we will extend the program to draw a filled hexagon. We use the Woopec library to do this. Visual Studio IntelliSense helps us understand the available commands.

  • How to easily write your first C# program with graphics (h4-02)

    I’ll start from the beginning and explain what you need to install on your computer and how to write your first C# program. We start here with turtle graphics, because it makes it easier to get started with programming. For programming we use Visual Studio. With the debugger of Visual Studio we can start the program and understand what it does.

  • Learn to fly with C# (h4-01)

    Is it easy to build an airplane? Of course it is: I can learn to make paper airplanes very quickly. But what’s the next step if I want to build a real airplane one day? For example, I can build a radio-controlled airplane. Is it easy to develop software? Sure: I can quickly learn to write a few small console programs. But what’s the next step? I have an idea…

  • Cache data in memory and update it regularly via a background service (.NET Core MinimalAPI example)

    Suppose we have a backend that takes a long time to collect and return the necessary data. Then it would make sense for the backend to cache the data so that it doesn’t always have to recalculate it. There are mature solutions for this (see for example Caching in .NET), but I have made my own small example here anyway, for the following reasons: I want the data to be generated in the background and the business code should be as decoupled as possible from the rest. Secondly an immediate update of the data should be possible. And last but not least I wanted to implement my own small minimal API example.

  • Serialization and deserialization of polymorphic objects with System.Text.Json and .NET 7

    Six months ago, I described how to serialize and deserialize polymorphic objects using System.Text.Json in .NET 6. This was a bit complicated in .NET 6. In .NET 7 it has improved significantly and is now quite simple.

  • Drawing spirograph curves (also called hypotrochoids) with C# turtle graphics

    Woopec: Drawing Spirograph Hypotrochoids with C# turtle (Link to Animation)

    A while back I owned a Spirograph Set that could be used to draw figures like the example above. Mathematicians also call such curves Hypotrochoids. In last post we drew polygons and stars with turtle graphics, now we draw spirograph curves. We use some more advanced Woopec features (transparent filling, individual shapes and synchronized turtles).

  • Drawing polygons and stars with C# turtle graphics (and GCD calculation)

    Woopec: Drawing stars with C# turtle graphics (Link to Animation)

    Suppose you have a fixed number of vertices. How can you connect them to a regular polygon or a star? Here we need some math: prime factorization and GCD (Greatest Common Divisor). And with Woopec C# Turtle Graphics we can then calculate and draw that.

  • IPC with polymorphic objects and System.Text.Json Serialization

    The task: I have two processes. Process A creates graphical objects, process B displays these objects on the screen. To do this, the objects must be transferred from A to B. The tools for this are quickly found: The objects can be serialized to a string with System.Text.Json in process A and deserialized in process B. Anonymous pipes can be used to transfer the strings from A to B. The difficulties lie in the details…

  • Woopec release 1.0.0

    As of today, the first version of the Woopec library is available on NuGet.

  • Turtle graphics for C#?

    C # is a great programming language with endless possibilities.

    There are great introductory pages for C# beginners - for example Learn to code C#. But getting started with graphics programming is not easy.

subscribe via RSS