Gemstone Common Library
Show/Hide TOC

# CollectionExtensionsMajorityBy TSource, TKey(IEnumerable TSource, Func TSource, TKey, Boolean, IEqualityComparer TKey) Method

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

## Definition

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

    public static TSource MajorityBy<TSource, TKey>(
    	this IEnumerable<TSource>? source,
    	Func<TSource, TKey> keySelector,
    	bool forwardSearch = true,
    	IEqualityComparer<TKey>? comparer = null
    )

VB
View Source Request Example

    <ExtensionAttribute>
    Public Shared Function MajorityBy(Of TSource, TKey) (
    	source As IEnumerable(Of TSource),
    	keySelector As Func(Of TSource, TKey),
    	Optional forwardSearch As Boolean = true,
    	Optional comparer As IEqualityComparer(Of TKey) = Nothing
    ) As TSource

C++
View Source Request Example

    public:
    [ExtensionAttribute]
    generic<typename TSource, typename TKey>
    static TSource MajorityBy(
    	IEnumerable<TSource>^ source,
    	Func<TSource, TKey>^ keySelector,
    	bool forwardSearch = true,
    	IEqualityComparer<TKey>^ comparer = nullptr
    )

JavaScript
View Source Request Example

    JavaScript does not support generic types or methods.

#### Parameters

source IEnumerable TSource
  An enumeration over which to find the majority element.
keySelector Func TSource, TKey
  A delegate that takes an object and produces the key for comparison.
forwardSearch Boolean (Optional)
  true to search forward in source; otherwise false to search backwards.
comparer IEqualityComparer TKey (Optional)
  The IEqualityComparerT implementation to use when comparing keys, or null to use the default comparer for the type of the key.

#### Type Parameters

TSource
  Type of elements in the source.
TKey
  The generic Type of the objects to be compared.

#### Return Value

TSource
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 TSource. 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
MajorityBy Overload
Gemstone.Collections.CollectionExtensions Namespace