Method Overriding in C#: virtual, override, base and new (.NET 10)

Method overriding in C#: through a Payment variable the overridden Fee runs the Card version while the hidden Label runs the base version

If you’ve written a Fee() method in a C# derived class and called it through a base-class variable, you’ve probably watched the base version run anyway, with a CS0108 warning in the build output. That’s because method overriding in C# takes two keywords: virtual on the base method and override on the derived one. Leave … Read more >>

Type Casting in C#: A Program to Demonstrate Every Conversion

Type casting in C#: a table comparing (int) cast, Convert.ToInt32 and int.Parse results for 12.97, 2.5, 3.5, "42", "abc" and null

Type casting in C# changes a value from one type to another. Widening casts like int to long happen implicitly, while narrowing casts like (int)12.97 need explicit syntax and can lose data: that one returns 12, not 13. In this tutorial, I’ll build up a little US shipping calculator and use it to show type … Read more >>

Method Overloading in C# (With Real-Time Examples)

Method overloading in C#: each Calculate call and the overload the compiler picks, with real .NET 10 results

Say you’re writing the checkout for an Austin outdoor store, and method overloading in C# is how one Calculate method takes whole dollars, a price with cents, or a price plus a custom tax rate. Quick answer: declare several methods with the same name but a different number, type or order of parameters. The compiler … Read more >>

foreach Loop in C#: Build a Sales Report Step by Step (.NET 10)

foreach loop in C#: iterating a string array of US states with foreach and Index() and the printed output

Every Monday our Dallas sales manager asks the same question: which state sold the most last week? A foreach loop in C# answers it in a few lines, because it visits every item in an array, list or dictionary without you managing an index. In this tutorial, I’ll build that sales-by-state report one step at … Read more >>