A Common Casting Pitfall in C# and How to Avoid It ⚠️

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

Thank you all for the helpful comments! 😊
You're right - using Cast<ICharacter>() is a simpler way to turn a list of Character into a list of ICharacter. Another great option is
Both methods make the code easier to read. You live and learn!
Thanks for pointing that out! I love seeing all the great suggestions.
Keep the feedback coming, and thanks for watching!

PatrickGod
Автор

Or simply declare List as List<ICharacter>

MaHo_
Автор

.Select(character => (ICharacter)character) can be changed to Cast<ICharacter>(), but declaring list as List<ICharacter> is better

PanSzelescik
Автор

Random question, I have a Blazor webapp with a calendar that lets users move events between days. This data comes from a dotnet API.
How would you suggest handling this webapp with multiple users/sessions? IE: when user1 moves an event then I want user2 to also see this change on their UI.

HoltBuzzing