C# method naming conventions: ToSomething vs. AsSomething

ToDictionary and ToList are prefixed with To because they don’t necessarily preserve the structural identity of the original collection or its properties.

  • Transforming a List<T> into a Dictionary<K, V> creates a collection with a whole new structure.
  • Transforming a HashSet<T> into a List<T> removes the uniqueness property of sets.

Methods prefixed with As don’t do any of these things – they simply provide an alternative view of the original collection. They enrich it.

Leave a Comment

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