| id | collections-and-tuples |
|---|---|
| title | Format collections and tuple names |
| sidebar_position | 18 |
| diataxis | how-to |
| persona | application developer |
import CodeBlock from '@theme/CodeBlock'; import collectionsTuples from '!!raw-loader!../_examples/scenarios-collections-tuples/Program.cs';
Collection humanization turns a sequence into a localized natural-language list. Pass a display selector when items are domain objects. Tuple helpers produce words such as double, triple, or quadruple for multiplicity labels; they do not transform a collection itself.
The executable formats strings, selects British English without changing ambient culture, projects a record to its display name, verifies the default formatter's null/blank filtering, and produces an invariant English tuple word:
{collectionsTuples}
The no-argument overload calls ToString for each item. Formatter overloads accept a function returning string or object. The default formatter trims each display result and drops null, empty, or whitespace-only results before deciding conjunction placement, punctuation, and the empty/singleton cases.
The separator argument represents the desired conjunction token, such as or; it is not simply a raw delimiter. For full application-wide customization, register an ICollectionFormatter at startup.
In Humanizer 4, pass a non-null CultureInfo to select the collection formatter
without changing CurrentCulture. For example, an en-GB formatter joins
three items without the Oxford comma. The explicit-culture overload accepts the
collection itself; when items need projection, select the display strings first
and then call Humanize(culture).
Tupleize returns fixed English names for common sizes and an n-tuple fallback. ToTuple(culture) uses the selected locale’s number-to-words converter where supported.
Collection output follows CurrentCulture; set it at the request or job
boundary. The default formatter silently removes null or blank display results,
so validate required source data before formatting. A custom formatter can
define a different contract. The collectionSeparator parameter on
TimeSpan.Humanize has different literal-separator semantics.
Collection humanization and tuple helpers span the documented corpus, while punctuation and localized tuple coverage vary by release. The executable compiles and runs against the selected package. The explicit-culture collection overload is available in the Humanizer 4 NuGet package.