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.
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'.
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.
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.
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.
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.
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.
How to Check If a String Is a Number in JavaScript
Learn how to check whether a string contains a valid number in JavaScript, with examples, pitfalls, and practical patterns.
How to Check Whether a File Is in Use in C#
Learn how to detect file locks in C#, why race conditions happen, and how to safely access files with retries and proper file sharing.
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.
How to Convert a Byte Array to a String in C#
Learn how to convert a byte array to a string in C#, including encoding, BinaryWriter behavior, and common mistakes with UTF-8 bytes.
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.
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.
How to Convert a UTF-8 byte[] to a String in Java
Learn how to convert a UTF-8 byte array to a String in Java, with examples, common mistakes, and real-world usage patterns.
How to Create a Byte Array from a Stream in C# (.NET)
Learn the preferred way to read a Stream into a byte array in C#, including MemoryStream, chunked copying, and common mistakes.
How to Create a Stream from a String in C#
Learn how to generate a Stream from a string in C# for unit tests, file-like input, and text processing with simple examples.
How to Create an Object Instance from a Type in C#
Learn how to create a new object instance from a Type in C# using Activator, reflection, and constructors with simple examples.
How to Enable Fusion Assembly Bind Failure Logging in .NET Framework
Learn how to enable Fusion assembly bind failure logging in .NET Framework, view logs, and troubleshoot assembly loading errors step by step.
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.
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.