Multi-Threaded Bank System?
Short answer: public class BankAccount { private object _lock = new object(); public decimal Balance { get; private set; } public void Deposit(decimal amount) { lock(_lock) { Balance += amount; } } public void Withdraw(decimal amount) { lock(_lock) { if (Balance >= amount) Balance -= amount; } } } Ensures thread safety and prevents financial inconsistency.
Example code
public class BankAccount
{
private object _lock = new object();
public decimal Balance { get; private set; }
public void Deposit(decimal amount)
{ lock(_lock) {
Balance += amount;
}
}
public void Withdraw(decimal amount)
{ lock(_lock) {
if (Balance >= amount)
Balance -= amount;
}
}
} Ensures thread safety and prevents financial inconsistency.
Real-world example (ShopNest)
Answer with: definition → one ShopNest-style story → trade-off → how you would verify it in production.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png