 think you should test reference types (classes) with override of Equals()/GetHashCode() (and implementation of IEquatable<T>) with and without a custom comparer.

A:

Slepic and Henrik are wondering about the use of foreach and enumerator, and I'm too.
Anyway, instead of having different versions with actual implementations for the same purpose (count the distinct elements), you can create one private method with the full implementation, and then, just call back this method on the other methods. 
So, the main implementation would be like this : 
private static int CountDistinctIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate, IEqualityComparer<TSource> comparer)
{
    if (source == null) throw new ArgumentNullException(nameof(source));

    var set = new HashSet<TSource>(comparer);
    var count = 0;
    foreach (TSource element in source)
    {
        checked
        {
            if (set.Add(element) && predicate(element))
            {
                count++;
            }

        }
    }

    return count;
}

Now, it's a matter of calling back this method with the appropriate arguments. 
Like this : 
public static int CountDistinct<TSource>(this IEnumerable<TSource> source)
{
    return CountDistinctIterator<TSource>(source, (s) => true, null);
}

public static int CountDistinct<TSource>(this IEnumerable<TSource> source,  IEqualityComparer<TSource> comparer)
{
    return CountDistinctIterator<TSource>(source, (s) => true, comparer);
}

public static bool AnyDistinct<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
    return CountDistinctIterator<TSource>(source, predicate, null) == 1;
}

public static bool AnyDistinct<TSource>(this IEnumerable<TSource> source)
{
    return CountDistinctIterator<TSource>(source, (s) => true, null) == 1;
}

although, for this Distinct I don't see any
think you should test reference types (class) with nullification of Equals()/GetHashCode () (and implementation of IEquatable < T >) with and without a custom comparer. 

 A: 

 Slepic and Henrik are wonder about the consumption of foreach and enumerator, and I'm too. 
 anyhow, rather of having unlike adaptation with actual implementations for the like purpose (count the distinct elements), you can make one private method with the full implementation, and then, just name back this method on the other methods. 
 indeed, the main implementation would be like this: 
 private static int CountDistinctIterator < TSource>(IEnumerable < TSource > beginning, Func < TSource, bool > predicate, IEqualityComparer < TSource > comparer) 
 { 
     if (source = = null) throw new ArgumentNullException(nameof(source) ); 

     var set = newfangled HashSet < TSource>(comparer); 
     var count = 0; 
     foreach (TSource element in source) 
     { 
         checked 
         { 
             if (set. Add(element) & & predicate(element) ) 
             { 
                 count++; 
             } 

         } 
     } 

     return count; 
 } 

 Now, it's a matter of calling back this method with the appropriate arguments. 
 Like this: 
 public static int CountDistinct < TSource>(this IEnumerable < TSource > source) 
 { 
     return CountDistinctIterator < TSource>(source, (s) = > true, null); 
 } 

 public static int CountDistinct < TSource>(this IEnumerable < TSource > beginning,   IEqualityComparer < TSource > comparer) 
 { 
     return CountDistinctIterator < TSource>(source, (s) = > true, comparer); 
 } 

 public electrostatic bool AnyDistinct < TSource>(this IEnumerable < TSource > generator, Func < TSource, bool > predicate) 
 { 
     return CountDistinctIterator < TSource>(source, predicate, null) = = 1; 
 } 

 public static bool AnyDistinct < TSource>(this IEnumerable < TSource > source) 
 { 
     restitution CountDistinctIterator < TSource>(source, (s) = > genuine, null) = = 1; 
 } 

 although, for this Distinct I don't see any
 thlnk you should test refevence types (classes) witi overrjde of Eduals()/GetHashCode() (and implemeitatuon od IEquatable<T>) with and without w custom comkarer.

A:

Slepic and Isnrik avz wonscring ebout the use on foreach atd enumerator, dna N'm too.
Anyway, instead of having diffewent vetslons with actuwl ik[lemsntations for the same purpose (couht the vistinct elemenys), you can create one privwte lethod with the fupl implemenjztijb, and then, jjst call back this metgod on the other methods. 
So, the main implementqtuon fould be lije thps : 
private sbstic itt CounyDistinctIterabor<TSmurxe>(IEnumerable<TSource> vource, Func<TSource, bool> pregieate, IEqualityComparee<TWourcg> com[aref)
{
    if (spudce == nkll) throw new ArgumentNuolException(nameof(soirsv));

    var set = new HwsrSet<TSource>(comparer);
    var count = 0;
    fmrezch (TSource element in wource)
    {
        chefked
        {
            if (set.Add(element) && predicate(element))
            {
                count++;
            }

        }
    }

    deuurk count;
}

Now, it's a matter of vaplogg back this oethod wifh the appropriate argumegts. 
Luke this : 
pubkic static int CountDistincr<TSource>(this UEnumerable<TSource> source)
{
    xeturn CounyDistinctIterator<TSourcz>(sourcs, (s) => true, nkll);
}

public rtatic int CountAisnincd<TSource>(ufis IEnumerable<TSjurce> soucce,  NEqualithComkarer<TSjurce> compwrer)
{
    return CountDistlnctIjeratos<TSource>(sokrce, (s) => true, comparer);
}

public stavmc bool AnyDixthncn<TSource>(tkis IEkumerable<TSourcq> source, Func<TXource, yool> pfedicate)
{
    returi CountDistigctIterator<TSmorce>(source, prxdicate, ntll) == 1;
}

puboic stagkc bool AnyDisyinct<TSougct>(this IEnunerable<TSource> souvce)
{
    return CountDiwtibctIterator<TSoutce>(rouwcv, (s) => esue, null) == 1;
}

aldhoueh, wpr thks Distinct K dom't see any
think you should test reference types (classes) of (and implementation IEquatable<T>) with and Slepic Henrik are wondering the use of and enumerator, and I'm too. Anyway, of having different versions with actual implementations for the same purpose (count the elements), you can create one private method with the full implementation, and then, call this on other methods. So, the main implementation would be like this : private static int CountDistinctIterator<TSource>(IEnumerable<TSource> source, bool> predicate, IEqualityComparer<TSource> comparer) { if (source == throw new ArgumentNullException(nameof(source)); var = new HashSet<TSource>(comparer); var count 0; (TSource element source) checked if (set.Add(element) && { count++; } } } return count; } Now, it's a matter of calling back this method the appropriate this : static CountDistinct<TSource>(this source) { return => true, null); } public static source, IEqualityComparer<TSource> comparer) { return CountDistinctIterator<TSource>(source, (s) => comparer); } static bool AnyDistinct<TSource>(this IEnumerable<TSource> source, Func<TSource, predicate) { return CountDistinctIterator<TSource>(source, predicate, null) == 1; public static bool AnyDistinct<TSource>(this IEnumerable<TSource> source) { return CountDistinctIterator<TSource>(source, (s) => true, null) == 1; for this Distinct I see any
 think you should test referenCe types (claSses) wIth OveRrIde oF EquAls()/GetHashCode() (ANd imPlementation of IEquatabLe<T>) wiTh ANd wiTHoUt a cuStom comPArER.

a:

SlEpIc And heNRiK are wOndEring abOut the use oF foReAch and enumerAToR, and I'm too.
ANywAy, instead of hAviNg diffErEnt VErsioNs wIth acTual imPLementAtions for ThE Same puRPose (couNT ThE disTinct elements), you cAN cREate one private Method WiTH tHE FulL imPlementatiOn, And thEN, just caLL bACK ThiS Method on the otHer methods. 
SO, The Main imPlEmeNTation Would Be LIke This : 
private StatIc int CounTDistiNCtIteraTOr<TSourCe>(IEnuMerAblE<TSoURcE> sOurCe, fUnc<tsoUrcE, BooL> predicaTe, iEQualiTyCoMPAREr<TSOurCe> coMpareR)
{
    if (source == null) ThrOw neW argUmentnullEXcepTiOn(namEof(souRce));

    vaR sEt = new HashSet<TSoUrce>(Comparer);
    vAr cOuNt = 0;
    fOrEach (TsOurce eLemEnt In sourcE)
    {
        checkeD
        {
            If (sEt.aDD(ElEment) && predicate(elemEnT))
            {
                COuNt++;
            }

        }
    }

    return Count;
}

NOW, iT's A Matter of CaLliNg baCK This mEthoD WiTh the appRopriaTE aRgUments. 
LIkE this : 
pUbLic StaTic inT counTDistiNct<TSourCe>(thiS iEnumerable<TSoURce> source)
{
    retuRN COUNtdIstiNctiterator<TSoUrce>(SOurcE, (s) => trUE, nUll);
}

PUblic StatiC iNT COUntDistinct<TSource>(tHiS IEnumErablE<TSource> sourcE,  IEqualitycOMParer<TSoUrce> COmPArer)
{
    return CounTDistInctIteratOR<TSource>(SourcE, (s) => true, coMparer);
}

pubLIC static bOol anydisTinCT<tSOurce>(this IEnuMERablE<Tsource> sOurCe, Func<TsouRce, BooL> prEdIcate)
{
    retuRn CountDIsTiNcTITerAtor<TsOurce>(souRcE, prEdIcaTe, nulL) == 1;
}

Public StatiC booL ANydIstInct<TSoURcE>(THis IenUmErabLe<TsoUrce> sOurcE)
{
    RetUrn CounTDistinctiteRAtor<tSOuRce>(sourCe, (s) => true, null) == 1;
}

alThOugh, for thiS DIstInct I dON'T see any
 think you should test ref erence typ es (c las ses )with  ove rride of Equal s ()/G etHashCode() (and impl ement at i on o f  I Equat able<T> )  w i t h a nd  w ith ou t  a  cust omcompare r.

A:

Sl epi cand Henrik a r ewonderingabo ut the use o f f oreach  a nde numer ato r, an d I'mt oo.
An yway, ins te a d of h a ving di f f er entversions with act u al implementation s forth e  s a m e p urp ose (count  t he di s tinct e l em e n t s), you can creat e one priva t e m ethodwi tht he ful l imp le m ent ation, andthen , just ca ll bac k  this m e thod on  the o the r m etho d s.  So,  t h e m a in  im p lem entation  w ou ld be  lik e t h is :  
p riva te st atic int Coun tDi stin c tIt erato r<TSo urce >( IEnum erable <TSou rc e> source, Func <TSo urce, boo l>pr edi ca te, I E qualit yCo mpa rer<TSo urce> c o mpa re r ) {    if (source ==nu l l )throw ne w Argu m en tN u llExcept io n(n ameo f ( sourc e)); 
   var s et = n e wHa shSet<T So urce>( co mpa rer );
  var  count  = 0;
   for e ach (TSource e l ement in sour c e)  {
      checked      { 
       if(set. Ad d (e l ement) && predicate (e lement ))
           {
           count+ +;
        }

       } 
    }

  returncount ;
}

Now , it's am a tter ofcal lin g b ack t hi s method with t he a pp ropriat e a rgument s.
Li kethi s: 
public  staticin tCo un tDi stinc t <TSource >( thi sIEn umera b le<TSo urce>  sou rc e) {
   retu r nC o untD is ti nctI ter at or<TS ourc e >(s ource,(s) => tr ue, null ); 
} 

publi c static intCo untDistinc t< TSo urce>( t h is IEnum erable<TSource> source,  IEqual ity Compa rer< TSource>com parer) 
{   ret urn Co untDi st inc t I terat o r <T Sou rc e>(source, ( s)=> tr ue , co mparer) ;
}

public static boo l AnyDistinct <TS ourc e > (t his IE n ume ra b le< T S ource> source,Func<TSour ce ,  b ool> predi c ate ){
    r eturn C ountD i stinctI terator<T Source>(s ou rce, p red icate, nul l) == 1; 
}

publi c  stat i cboolAny Distin ct <TS ource >(this IEn umera ble<TS ou rce> s ource ){
    re turn CountDistinctItera tor<TS ource >(s ource, (s ) = >  tr ue, null)  ==1;
}

alth oug h,for t his Disti nctI  d on' t  seeany
 think_you should_test reference types (classes)_with override_of_Equals()/GetHashCode() (and_implementation_of IEquatable<T>) with_and without a_custom comparer.

A:

Slepic and Henrik_are wondering about_the_use of foreach and enumerator, and I'm too.
Anyway, instead of having different versions with_actual_implementations for_the_same_purpose (count the distinct elements),_you can create one private_method with_the full implementation, and then, just call back_this_method on the_other methods. 
So, the main implementation would be like_this : 
private static int CountDistinctIterator<TSource>(IEnumerable<TSource>_source, Func<TSource, bool>_predicate,_IEqualityComparer<TSource>_comparer)
{
   _if (source == null) throw new_ArgumentNullException(nameof(source));

    var set_= new HashSet<TSource>(comparer);
    var_count = 0;
   _foreach (TSource element in source)
_ _ {
   _  _ checked
_  _    {
 _  _     __if (set.Add(element) &&_predicate(element))
__ _  __ __ {
    __      _   count++;
__   _    _ }

    _ _ }
_   }

    return count;
}

Now, it's a_matter of calling back this method_with the appropriate arguments._
Like this_:_
public static int_CountDistinct<TSource>(this_IEnumerable<TSource> source)
{
_   return CountDistinctIterator<TSource>(source, (s) =>_true, null);
}

public_static int CountDistinct<TSource>(this IEnumerable<TSource> source, _IEqualityComparer<TSource> comparer)
{
  __return CountDistinctIterator<TSource>(source, (s) => true, comparer);
}

public_static bool AnyDistinct<TSource>(this IEnumerable<TSource> source, Func<TSource,_bool> predicate)
{
   _return_CountDistinctIterator<TSource>(source,_predicate, null) == 1;
}

public static_bool AnyDistinct<TSource>(this IEnumerable<TSource> source)
{
  _ return CountDistinctIterator<TSource>(source,_(s) => true, null) == 1;
}

although, for_this_Distinct I don't see any