effective C# notes
what I tried to learn while reading Effective C#. Kinda pointless now since I don't use C# that often anymore. I got to the LINQ chapter and gave up lmao.
- Multicast Delegates i.e Delegates with multiple methods attached to it are apparently a thing.
- The Null conditional operator for events invocations.
- Used to check if the EventName has any handlers before invoking it.
- Is way more complicated than just simply checking
EventName != null.
Replace your hard-coded stringly-typed variable names with
nameof(var). Instead of getting runtime errors saying how the compiler couldn't find the variable, you'll get compile-time errors instead!
Avoid boxing and unboxing. Use generics instead.
- Boxing is when C# tries to morph value types (int, classes, etc.) into the System.Object type through a performance-robbing operation.
- It's when you use a value type when a reference type is expected, boxing happens.
- I.e do explicit type conversions, don't let the compiler implicitly do it for you.
- i.e use your
- i.e use your
When creating class methods, make the
virtualonly if you want derived classes to implement their behavior. Don't just throw
virtualaround like it's nothing.
newmodifier is a headache. It seems to be related to polymorphism and base classes but I can't seem to wrap my head around it fully.
- The author says use it carefully but I still have no idea what it even does.
newexplicits hides a member that is derived from a base class. Seems like this is a band-aid for subclasses to hide unwanted inherited features.
newcreates a member of the same name in the subclass to hide the base class implementation.
overrideextends the base class implementation.
- This kinda solves the confusion.
- It really matter how you're trying to retrieve information.