ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ToPlural

Returns the plural form of the specified word.

Source

/// <summary>
/// Returns the plural form of the specified word.
/// </summary>
/// <param name="count">How many of the specified word there are. A count equal to 1 will not pluralize the specified word.</param>
/// <returns>A string that is the plural form of the input parameter.</returns>
public static string ToPlural(this string @this, int count = 0)
{
    return count == 1 ? @this : System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US")).Pluralize(@this);
}

Example

"goose".ToPlural(); // returns "geese"
"wolf".ToPlural(); // returns "wolves"

String.Format("{0} {1}", commentCount, "comment".ToPlural(commentCount)); // returns "1 comment" or "2 comments"

Author: Shawn Miller

Submitted on: 3 feb. 2011

Language: C#

Type: System.String

Views: 8637