Questions

C# questions

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

AddTransient vs AddScoped vs AddSingleton in ASP.NET Core Dependency Injection

Learn the differences between AddTransient, AddScoped, and AddSingleton in ASP.NET Core DI with examples and practical usage.

csharpasp.net-core.net-core

C# Type Checking Explained: typeof vs GetType() vs is

Learn when to use typeof, GetType(), and is in C#. Understand exact type checks, inheritance, and safe type testing clearly.

csharptypestypeofgettype

C# Version Numbers Explained: C# vs .NET Framework and Why “C# 3.5” Is Incorrect

Learn the correct C# version numbers, how they map to .NET releases, and why terms like C# 3.5 are inaccurate and confusing.

csharp.netvisual-studio.net-core

C# foreach Closure Behavior Explained: Why Loop Variables Were Reused

Learn why C# foreach loop variables once caused closure bugs, how the compiler handled scope, and what changed in newer C# versions.

csharpforeachlambdascope

Case-Insensitive String.Contains in C#

Learn how to make string.Contains case-insensitive in C#, including StringComparison, examples, pitfalls, and real-world usage.

csharpstringcontainscase-insensitive

Const vs Readonly in C#: What's the Difference and When to Use Each

Learn the difference between const and readonly in C#, when each is evaluated, and how to choose the right one in real code.

csharp.netconstantsreadonly

Convert Byte Arrays to Hex Strings in Java

Learn how to convert a byte array to a hexadecimal string and back in Java with clear examples, common mistakes, and practical use cases.

csharparrayshex

Create Excel Files in C# Without Microsoft Office Installed

Learn how to create .XLSX and .XLS files in C# without installing Microsoft Office using common libraries and practical examples.

csharp.netexcelfile-io

Deep Copy and Object Cloning in C#

Learn how deep copying and object cloning work in C#, with practical examples, pitfalls, and safe ways to duplicate objects.

csharp.netclonedeep-copy

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 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 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

Page 1 of 2 - 32 questions

PreviousNext