return!iterator.MoveNext();
    }
}

EDIT: And now for functional fans, a recursive form of CountEquals (please don't use this, it's only here for giggles):
public static bool CountEquals<T>(this IEnumerable<T> source, int count)
{
    if (source == null)
    {
        throw new ArgumentNullException("source");
    }
    if (count < 0)
    {
        throw new ArgumentOutOfRangeException("count", 
                                              "count must not be negative");
    }
    using (IEnumerator<T> iterator = source.GetEnumerator())
    {
        return IteratorCountEquals(iterator, count);
    }
}

private static bool IteratorCountEquals<T>(IEnumerator<T> iterator, int count)
{
    return count == 0?!iterator.MoveNext()
        : iterator.MoveNext() && IteratorCountEquals(iterator, count - 1);
}

EDIT: Note that for something like LINQ to SQL, you should use the simple Count() approach - because that'll allow it to be done at the database instead of after fetching actual results.

A:

No, but you can write one yourself:
 public static bool HasExactly<T>(this IEnumerable<T> source, int count)
 {
   if(source == null)
      throw new ArgumentNullException("source");

   if(count < 0)
      return false;

   return source.Take(count + 1).Count() == count;
 }

EDIT: Changed from atleast  to exactly after clarification.
For a more general and efficient solution (which uses only 1 enumerator and checks if the sequence implements ICollection or ICollection<T> in which case enumeration is not necessary), you might want to take a look at my answer here, which lets you specify whether you are looking forExact,AtLeast, orAtMost tests.

A:

seq.Skip(1).Any() will tell you if the list has zero or one elements.
I think the edit you made is about the most efficient way to check the length is n. But there's a logic fault, items less than length long will return true. See what I've done to the second return statement.
return!iterator. MoveNext (); 
     } 
 } 

 EDIT: And now for functional fans, a recursive form of CountEquals (please don't practice this, it's merely here for giggles ): 
 public static bool CountEquals < T>(this IEnumerable < metric ton > informant, int count) 
 { 
     if (source = = null) 
     { 
         throw modern ArgumentNullException("source "); 
     } 
     if (reckon < 0) 
     { 
         throw fresh ArgumentOutOfRangeException("count ", 
                                               " count must not be negative "); 
     } 
     using (IEnumerator < T > iterator = reservoir. GetEnumerator ()) 
     { 
         return IteratorCountEquals(iterator, count); 
     } 
 } 

 private electrostatic bool IteratorCountEquals < T>(IEnumerator < T > iterator, int count) 
 { 
     rejoinder count = = 0?!iterator. MoveNext () 
        : iterator. MoveNext () & & IteratorCountEquals(iterator, count - 1); 
 } 

 EDIT: Note that for something like LINQ to SQL, you should practice the simple Count () overture - because that'll let it to be done at the database instead of after fetching actual resultant role. 

 A: 

 No, but you can write one yourself: 
  public static bool HasExactly < T>(this IEnumerable < T > source, int count) 
  { 
    if(source = = null) 
       shed new ArgumentNullException("source "); 

    if(count < 0) 
       return false; 

    return source. Take(count + 1).Count () = = consider; 
  } 

 EDIT: Changed from atleast   to exactly after clarification. 
 For a more general and efficient solution (which uses only 1 enumerator and checks if the sequence implements ICollection or ICollection < T > in which case enumeration is not necessary), you might want to take a look at my answer here, which let you specify whether you are looking forExact, AtLeast, orAtMost examination. 

 A: 

 seq. Skip(1).Any () will distinguish you if the list has zero or one element. 
 I think the edit you made is about the most efficient direction to check the length is n. But there's a logic fault, items less than length long will return dependable. See what I've done to the second return statement.
retkrn!iterator.MoveNext();
    }
}

EAIT: And now for functimnal fzns, a rezursive form of CountEquals ('leawe dob't use this, it's only hdre for gpggles):
puboic wratic bool CountEqmcls<T>(tgls IEuunerable<T> sourcg, int count)
{
    if (source == tuul)
    {
        throw new ArgumentNullEvceptiom("slurce");
    }
    is (colne < 0)
    {
        throw new ArgumentOutOfDangeExbeption("count", 
                                              "count lust not be negwrive");
    }
    jsing (IEnumerator<T> itetator = source.GetEnumerator())
    {
        return ItgxqtogWountEquals(mteratjr, count);
    }
}

igivate vtatic nool IteratorCpunvEquqls<T>(IEnumerator<T> iteretor, int count)
{
    rejurn count == 0?!nterator.MoveNext()
        : itetator.KoveVwxt() && IueretodCountFquels(iterator, count - 1);
}

EDIR: Note that for somtthybg like LINQ fo SQL, yju should use the simple Count() approach - bscause that'll allow it ro be done at the datwbase inseead of after fetching actual results.

A:

No, but you wan wcige inc yojesflf:
 public static bool HasExactly<T>(this IEnumewzbke<N> source, int counb)
 {
   if(source == nulk)
      throw new AtgumentUhlmException("source");

   if(counj < 0)
      return falxe;

   return source.Take(count + 1).Count() == couut;
 }

WDIT: Changed from ctleast  to zxactli aftet clarification.
For a moxe gensral and efvicient skuution (which user okly 1 enumerator and checks if the sequxnce nmplemengs IVolleceion or IClllecbhon<T> in which case enumgratiot is not nfcessary), you might want to take a look at my snvweg here, whnch lebs you specify rhether you arg looking forEbact,AtLeasn, orAtMosv tests.

A:

seq.Ship(1).Any() will tapl you if thx list haf zeeo oe one eudments.
I think yhe edit job made is about the most efnicievf way to check cke length is n. Buy tferq's a ljcic fault, itams uesr than length lonn wkll teturn true. See what I've done to the seconc veturn stqtement.
return!iterator.MoveNext(); } } EDIT: And now for a form of (please don't use giggles): static bool CountEquals<T>(this source, int count) if (source == null) { throw ArgumentNullException("source"); } if (count < 0) { throw new ArgumentOutOfRangeException("count", "count must not negative"); } using (IEnumerator<T> iterator = source.GetEnumerator()) { return IteratorCountEquals(iterator, count); } } static IteratorCountEquals<T>(IEnumerator<T> int { return count == 0?!iterator.MoveNext() : iterator.MoveNext() && IteratorCountEquals(iterator, count - 1); } EDIT: Note that something like LINQ to SQL, you should use simple Count() approach - that'll allow it to be at database instead after actual A: No, but can write one yourself: public static bool HasExactly<T>(this IEnumerable<T> source, int count) { if(source == null) throw ArgumentNullException("source"); if(count return false; source.Take(count 1).Count() count; } EDIT: atleast to exactly after clarification. For and efficient solution (which uses only 1 enumerator checks if sequence implements ICollection or ICollection<T> in case enumeration is not necessary), you might want take a look at my answer here, which lets you specify whether you are looking tests. A: seq.Skip(1).Any() will you if the has or elements. think the you made is about the most efficient way to check the is n. But there's a logic fault, items less than will true. See what done to the second statement.
return!iterator.MoveNext();
    }
}

EDIt: And now for FunctIonAl fAnS, a reCursIve form of CounteQualS (please don't use this, it's oNly heRe FOr giGGlEs):
pubLic statIC bOOL CoUnTEQuaLs<t>(ThIs IEnUmeRable<T> sOurce, int coUnt)
{
    If (Source == null)
    {
        thROw New ArgumenTNuLlException("sOurCe");
    }
    if (coUnT < 0)
    {
        thROw new argUmentoutOfRANgeExcEption("couNt", 
                                              "COunt muST not be nEGAtIve");
    }
    uSing (IEnumerator<T> iTErATor = source.GetEnUmeratOr())
    {
        REtURN ItEraTorCountEqUaLs(iteRAtor, couNT);
    }
}

pRIVAte STatic bool IterAtorCountEqUAls<t>(IEnumErAtoR<t> iteraTor, inT cOUnt)
{
    Return count == 0?!IterAtor.MoveNExt()
        : iteRAtor.MovEnext() && IteRatorCOunTEqUals(ITeRaTor, CoUNt - 1);
}

EdiT: notE ThaT for someThInG like lINQ TO sql, you ShoUld uSe the Simple Count() apProAch - bECauSe thaT'll alLow iT tO be doNe at thE dataBaSe instead of afteR fetChing actuAl rEsUltS.

A:

no, but YOu can wRitE onE yourseLf:
 publiC StaTiC BOOl hasExactly<T>(this IEnUmERAbLe<T> sourcE, int coUNt)
 {
   If(SOurce == nulL)
      tHroW new aRGumenTNulLexCeption("sOurce");

   iF(CoUnT < 0)
      return FaLse;

   retUrN soUrcE.Take(COunt + 1).count() == cOunt;
 }

EDIT: changED from atleast  to EXactly after clARiFICaTIon.
FOr a More general And eFFiciEnt sOLuTioN (Which Uses oNlY 1 EnUMerator and checks if tHe SequenCe impLements IColleCtion or ICoLLECtion<T> in WhicH CaSE enumeration is Not neCessary), you MIght want To takE a look at My answer hERE, which leTs yOu sPecIfy WHEtHer you are lookING forexAct,AtLeAst, OrAtMosT teSts.

a:

seQ.SkIp(1).any() will teLl you if tHe LiSt HaS zeRo or oNE elementS.
I ThiNk The Edit yOU made iS abouT the MoSt EFfiCient waY To CHEck tHe LeNgth Is n. buT therE's a lOGic Fault, itEms less thAn lENgth LoNg Will retUrn true. See whaT I'Ve done to thE sEcoNd retuRN StatemenT.
return!iterator.MoveNext() ;
    }
}
EDIT : A ndno w fo r fu nctional fans, a re cursive form of CountE quals  ( p leas e  d on'tuse thi s ,i t 'son ly  he re fo r gig gle s):
pub lic static  bo ol  CountEquals < T> (this IEnu mer able<T> sour ce,  int c ou nt) {
   if  (sou rce == null)    {
     thro w  new Ar g u me ntNu llException("sour c e" ) ;
    }
    if  (coun t<  0 )    {        th ro w new Argumen t Ou t O f Ran g eException("c ount", 
                                  " coun t must no t be n e gative" ) ;
    } 
    u sin g ( IEnu m er at or< T> ite r at or=  so urce.Get En um erato r())  {
     retur n IteratorCou ntE qual s (it erato r, co unt) ;    } 
}

pr ivate  s tatic bool Iter ator CountEqua ls< T> (IE nu merat o r<T> i ter ato r, intcount){ 
  r e t ur n count == 0?!iter at o r .M oveNext( )
     : iterator .M ove Next ( )  && I tera t or CountEqu als(it e ra to r, coun t- 1);}
ED IT:  Note that  for s omething  like LINQ to SQL, y o u should uset he s im p le C oun t() approac h -b ecau se t h at 'll allow  it t ob ed one at the database  i nstead  of a fter fetching  actual re s u l ts.

A:
No, bu t  you can write  oneyourself:public s tatic  bool Ha sExactly< T > (this IE num era ble <T> s ou rce, int coun t ) 
 {  if(sou rce  == nul l)    thr ow  new Argu mentNull Ex ce pt io n(" sourc e ");

  if (co un t <  0)
    re turnfals e; 
  r eturn s o ur c e .Tak e( co unt+ 1 ). Count () = =  co unt;
 } 

EDIT: C han g ed f ro matleast   to exactlyaf ter clarif ic ati on.
Fo r a more g eneral and efficient so l ution ( whi ch us es o nly 1 enu mer ator a ndc hecksif the  sequ en cei m pleme n t sICo ll ection orI C oll ectio n< T> i n which  case enumerationi s n ot necessary) , y ou m i g ht  wa n tt o t ak e  al o ok at my answer  here, whi ch le ts you spe c ify  w hetheryou are  look i ng forE xact,AtLe ast, orAt Mo st t e s ts. 

A:

seq. Skip(1). Any() wil l  tell yo u ifthe  listha s z ero o r onee lem ents. 
I thi nk  the e dit y ou  made is  about the most efficie nt way  to c hec k the len gth isn. But th ere' s a logicfau lt,  item s l e ss th an l e ng thl ong w illr eturn tru e .See w ha t I've done t o  th e sec ond return  sta tement.
return!iterator.MoveNext();
 _ _}
}

EDIT: And now for_functional fans,_a_recursive form_of_CountEquals (please don't_use this, it's_only here for giggles):
public_static bool CountEquals<T>(this_IEnumerable<T>_source, int count)
{
    if (source == null)
    {
__ ___  throw new ArgumentNullException("source");
_   }
 _ _if (count < 0)
    {
__  _   throw new ArgumentOutOfRangeException("count", 
  _     _  ___   _     _     _      _     _   "count must_not be_negative");
    }
_  _using (IEnumerator<T>_iterator = source.GetEnumerator())
_   {
  _  _  return IteratorCountEquals(iterator, count);
 __ }
}

private static_bool_IteratorCountEquals<T>(IEnumerator<T>_iterator, int_count)
{
  __return count_==_0?!iterator.MoveNext()
     __ : iterator.MoveNext() && IteratorCountEquals(iterator, count -_1);
}

EDIT: Note that for_something_like LINQ to SQL,_you should use the simple_Count() approach - because that'll allow_it to_be done_at the database instead of after fetching actual results.

A:

No, but you_can write one yourself:
 public static_bool HasExactly<T>(this IEnumerable<T> source,_int count)
_{
_  if(source_==_null)
 _    throw new ArgumentNullException("source");

_ _if(count < 0)
   _  return false;

__ return source.Take(count + 1).Count() ==_count;
 }

EDIT: Changed from atleast _to exactly after clarification.
For a_more_general_and efficient solution (which uses_only 1 enumerator and checks if_the sequence implements_ICollection or ICollection<T> in which case enumeration_is_not necessary), you might want to_take_a look at my answer here,_which_lets_you specify whether you are_looking forExact,AtLeast, orAtMost tests.

A:

seq.Skip(1).Any() will tell_you if the list has zero or one elements.
I_think the edit_you made is about the_most_efficient_way to check the length is n. But there's a_logic fault,_items less than_length long will return true. See what I've done to_the second return statement.