Blog

posts from 2020

WinUI NumberBox Control

0 Comments
By Fons Sonnemans, 27-mrt-2020

If you write business apps, there are a lot of controls for data input: TextBox, CheckBox, ComboBox, DatePicker, ToggleSwitch, TimePicker, RadioButton, Slider, etc. I always wondered why there was no NumberBox. Numeric input is very common so it needs its own control for it. Luckily there is the Windows UI Library (WinUI), an open source project from Microsoft. I proposed the NumberBox last year and the team did a great job implementing it. It is released in version 2.3 and most of the issues are now solved. Time for a blog post showing of its features.

This animated GIF demonstrates a few of the features like AcceptsExpression, PlaceholderText, SpinButtons and NumberFormatter. I 'stole' it from this tweet.

NumberBox in action

READ MORE

C# boxing with string concatenation and interpolation

5 Comments
By Fons Sonnemans, 10-jan-2020

C# boxing with String concatenation and interpolation

Boxing is evil and you should always try to avoid it. That is what I tell my students in my C# training. But what is boxing and how do you avoid it. Boxing is wrapping a value type (struct) inside a reference type (object or interface) variable.

using System;

namespace BoxingDemo {
    class Program {
        static void Main(string[] args) {
            int a = 5;
            object b = a;      // boxing
            IComparable c = a; // boxing
            int d = (int)b;    // unboxing, also evil (slow)
        }
    }
}

Boxing is evil because it is “slow”. It creates a reference type (the boxed value) which the garbage collector has to clean up (which is also “slow”). I will first explain how you can detect boxing and then how to avoid it when using string concatenation and interpolation.

READ MORE

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.