Why is it considered bad to expose List? [duplicate]

I agree with moose-in-the-jungle here: List<T> is an unconstrained, bloated object that has a lot of “baggage” in it. Fortunately the solution is simple: expose IList<T> instead. It exposes a barebones interface that has most all of List<T>‘s methods (with the exception of things like AddRange()) and it doesn’t constrain you to the specific List<T> … Read more

CA2202, how to solve this case

You should suppress the warnings in this case. Code that deals with disposables should be consistent, and you shouldn’t have to care that other classes take ownership of the disposables you created and also call Dispose on them. [SuppressMessage(“Microsoft.Usage”, “CA2202:Do not dispose objects multiple times”)] public static byte[] Encrypt(string data, byte[] key, byte[] iv) { … Read more