If I'm using non-generic collections, functions and so on then passed value types will be boxed because of casting to Object (that is not good for performance). But after including generics in C# 2.0 most situations of passing value type as Object was obviated.
Are there still any situations in competent programming where it's not possible to accomplish something with generics and still need to use casting to Object? If so can you please show an example? Thanks.
The use of System.Object offers flexibility (at the cost of performance).
Consider the storage mechanisms of ASP.NET (Session and Application), they have the general structure of
Dictionary<string, object> PropertyBag;
And you would use them like
PropertyBag["currentCustomer"] = aCustmer;
PropertyBag["visits"] = 0;
It's not possible to replace object with something stronger typed here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With