Constructor in C#: Every Type with Real Examples (.NET 10)

Constructor in C#: code card showing a derived class calling base() and the terminal output with the base constructor running first

Say you’re building order intake for a Seattle coffee roaster. Every order needs a customer, a five-digit ZIP code and at least one pound of beans, and a half-built order should never exist. Quick answer: a constructor in C# is the method named after the class, with no return type, that runs on new. That’s … Read more >>

ArrayList in C#: Add, Sort, Search, Casting and List<T> (.NET 10)

ArrayList in C#: an ArrayList holding a string, an int and a decimal, where (double)row[2] throws InvalidCastException

An ArrayList in C# is a resizable list from System.Collections that stores everything as object. Create it with new ArrayList(), call Add, and cast each item back when you read it: Output: I ran every example below on .NET 10, including the casting errors, and finished by converting the list to the List<T> Microsoft recommends … Read more >>

OOPs Concepts in C# with Real Examples (.NET 10)

OOPs concepts in C#: table mapping encapsulation, inheritance, polymorphism, abstraction and interfaces to C# keywords on a bank account model

Say you’re coding accounts for a small Columbus, Ohio credit union. Checking pays a $5 fee under $1,500, savings earns 3% a year, and nobody may type a balance in directly. Those rules map straight onto the OOPs concepts in C#: a class for the account, encapsulation to guard the balance, inheritance and polymorphism for … Read more >>

Convert Char Array to String in C# (6 Ways, .NET 10)

Convert char array to string in C#: ['A','u','s','t','i','n'] becomes "Austin" with new string(city)

To convert a char array to string in C#, pass the array to the string constructor: new string(chars). It copies every character into a new string in one call. If you’ve tried chars.ToString() first, you’ve probably seen System.Char[] instead of your text. Arrays don’t override ToString(), so you get the type name. I ran every … Read more >>