C# Automatic Properties

Properties can have code put into them without breaking contract, fields can’t have code put into them without changing them to properties (and breaking the interface). Properties can be read only or write only, fields can’t. Properties can be data bound, fields can’t.

object to string array

You can use the fact that every array implements IEnumerable: string[] arr = ((IEnumerable)obj).Cast<object>() .Select(x => x.ToString()) .ToArray(); This will box primitives appropriately, before converting them to strings. The reason the cast fails is that although arrays of reference types are covariant, arrays of value types are not: object[] x = new string[10]; // Fine … Read more

List readonly with a private set

I think you are mixing concepts. public List<string> myList {get; private set;} is already “read-only”. That is, outside this class, nothing can set myList to a different instance of List<string> However, if you want a readonly list as in “I don’t want people to be able to modify the list contents“, then you need to … Read more

What is the best resource for learning C# expression trees in depth?

Chapter 11 (Inside Expression Trees) and chapter 12 (Extending Linq) of Programming Microsoft Linq (ISBN 13: 978-0-7356-2400-9 or ISBN 10: 0-7356-2400-3) has been invaluable for me. I haven’t read Jons book, but he is a quality guy and explains things well, so I assume that his coverage would also be good. Another great resource is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)