Stage 6 - Exceptions, Async, and Resources
Q37. What is exception handling?
Quick interview answer:
Exception handling means handling runtime errors in a controlled way.
In C#, we use try, catch, and finally so the application can show a useful message, log the error, or clean up resources.
Study in detail: Exceptions - This article expands the topic with complete explanation, examples, and practice code.
Q38. What is the difference between Parse and TryParse?
Quick interview answer:
Parse converts text to another type but throws an exception if the value is invalid.
TryParse returns true or false, so it is safer for user input like marks, age, or fee amount.
Study in detail: Exceptions - This article expands the topic with complete explanation, examples, and practice code.
Q39. What is IDisposable?
Quick interview answer:
IDisposable is used to release resources that need manual cleanup, like files, streams, and database connections.
We usually use it with a using statement so cleanup happens automatically.
Study in detail: IDisposable - This article expands the topic with complete explanation, examples, and practice code.
Q40. What is async/await?
Quick interview answer:
async and await help C# wait for slow operations without blocking the thread.
They are commonly used for database calls, API calls, and file operations, especially in ASP.NET Core applications.
Study in detail: Async and await - This article expands the topic with complete explanation, examples, and practice code.
Q41. Why should we avoid async void?
Quick interview answer:
We should avoid async void because the caller cannot await it and exception handling becomes difficult.
Use async Task for async methods. The main acceptable use of async void is UI event handlers.
Study in detail: Async and await - This article expands the topic with complete explanation, examples, and practice code.
Q42. What is the difference between Task and Thread?
Quick interview answer:
Thread is a low-level operating system thread. Task is a higher-level abstraction for work that may run asynchronously or on the thread pool.
In modern C#, Task is preferred because it works naturally with async and await.
Study in detail: Multithreading - This article expands the topic with complete explanation, examples, and practice code.