Questions

C# questions

Choose a question page, learn the concept, then test your understanding with a quiz.

How to Calculate Age from a DateTime Birthday in C#

Learn how to calculate a person's age in years from a DateTime birthday in C# with clear logic, examples, pitfalls, and best practices.

csharp.netdatetime

How to Calculate Relative Time in C#

Learn how to display relative time in C# from a DateTime value, such as '2 hours ago', '3 days ago', or 'a month ago'.

csharpdatetimetimerelative-time-span

How to Calculate the Difference Between Two Dates in C#

Learn how to calculate the number of days between two dates in C# using DateTime and TimeSpan with clear examples and common pitfalls.

csharpdate

How to Call One Constructor from Another in C#

Learn constructor chaining in C#: call one constructor from another, avoid duplication, and initialize readonly fields correctly.

csharpconstructor

How to Call a Base Class Constructor in C#

Learn how to call a base class constructor in C#, including Exception examples, syntax, common mistakes, and practical usage.

csharp.netinheritanceconstructor

How to Cast an int to an Enum in C#

Learn how to cast an int to an enum in C#, when it works, how to validate values, and common mistakes to avoid.

csharpenumscastinginteger

How to Catch Multiple Exceptions at Once in C#

Learn how to catch multiple exceptions in C#, avoid repetitive catch blocks, and choose cleaner patterns like exception filters and TryParse.

csharp.netexception

How to Constrain a Generic Type to Enum in C#

Learn how to constrain generic methods to enum types in C#, parse enum values safely, and provide defaults with case-insensitive matching.

csharpgenericsenumsgeneric-constraints

How to Convert a C# Object to a JSON String in .NET

Learn how to serialize C# objects to JSON in .NET using built-in options and JSON.NET, with examples, pitfalls, and best practices.

csharp.netjsonserialization

How to Convert a String to an Enum in C#

Learn how to convert a string to an enum in C# using Enum.Parse and Enum.TryParse, with examples, mistakes, and best practices.

csharpstringenums

How to Encode and Decode Base64 Strings in JavaScript

Learn how to encode and decode Base64 strings in JavaScript, including browser and Node.js examples, common mistakes, and practical use cases.

csharpbase64

How to Enumerate an Enum in C#

Learn how to enumerate enum values in C# using Enum.GetValues, foreach, and practical examples with common mistakes explained clearly.

csharp.netloopsenums

How to Generate a Random Integer in C#

Learn how to generate random integers in C# using Random, understand ranges, avoid common mistakes, and see practical examples.

csharprandom

How to Get the Integer Value from an Enum in C#

Learn how to get an int value from an enum in C#, cast enums safely, and pass enum values into methods with practical examples.

csharpenumscastingint

How to Give a C# Auto-Property an Initial Value

Learn how to initialize C# auto-properties, when to use constructors, and the modern property initializer syntax with clear examples.

csharpconstructorgettersetter

How to Iterate Over a Dictionary in C#

Learn the standard ways to iterate over a Dictionary in C#, including KeyValuePair, keys, values, and common beginner mistakes.

csharpdictionaryloops

How to Loop Through Enum Values in C#

Learn how to iterate over all enum values in C# using Enum.GetValues, with examples, common mistakes, and practical use cases.

csharp.netenumslanguage-features

How to Mark a Method as Obsolete or Deprecated in C#

Learn how to deprecate methods in C# using the Obsolete attribute, with examples, warnings vs errors, and migration tips.

csharp.netversioningdeprecated

How to Send an HTTP POST Request in .NET

Learn how to send HTTP POST requests in .NET, including JSON bodies, form data, headers, and best practices with HttpClient.

csharp.netposthttpwebrequest

How to Sort a List<T> by an Object Property in C#

Learn how to sort a List<T> by object properties in C# using Sort, LINQ OrderBy, ThenBy, and custom comparisons.

csharpgenericslistsorting

Page 2 of 4 - 62 questions