Gemstone Common Library
Show/Hide TOC

# CollectionExtensionsMajority T(IEnumerable T, T, Boolean, IEqualityComparer T) Method

Returns the majority value in the collection, or defaultValue if no item represents the majority.

## Definition

Namespace: Gemstone.Collections.CollectionExtensions
Assembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.173 -- Release Build+298e1c238b074757f82f41812034645402a162ed
C#
View Source Request Example

    public static T Majority<T>(
    	this IEnumerable<T>? source,
    	T defaultValue,
    	bool forwardSearch = true,
    	IEqualityComparer<T>? comparer = null
    )

VB
View Source Request Example

    <ExtensionAttribute>
    Public Shared Function Majority(Of T) (
    	source As IEnumerable(Of T),
    	defaultValue As T,
    	Optional forwardSearch As Boolean = true,
    	Optional comparer As IEqualityComparer(Of T) = Nothing
    ) As T

C++
View Source Request Example

    public:
    [ExtensionAttribute]
    generic<typename T>
    static T Majority(
    	IEnumerable<T>^ source,
    	T defaultValue,
    	bool forwardSearch = true,
    	IEqualityComparer<T>^ comparer = nullptr
    )

JavaScript
View Source Request Example

    JavaScript does not support generic types or methods.

#### Parameters

source IEnumerable T
  An enumeration over which to find the majority element.
defaultValue T
  Default value to return if no item represents the majority.
forwardSearch Boolean (Optional)
  true to search forward in source; otherwise false to search backwards.
comparer IEqualityComparer T (Optional)
  The IEqualityComparerT implementation to use when comparing keys, or null to use the default comparer for the type of the key.

#### Type Parameters

T
  Type of elements in the source.

#### Return Value

T
The majority value in the collection.

#### Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable T. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

## See Also

#### Reference

CollectionExtensions Class
Majority Overload
Gemstone.Collections.CollectionExtensions Namespace