Home > Interviews > LINQ >

What is the difference between Count() and LongCount() extension methods in LINQ ?

 Posted by Akiii on 3/6/2012 | Category: LINQ Interview questions | Views: 3384 | Points: 40
Answer:

    

public static long display()
{
var tempval = (from h in objDB.tbl_mvc_login
select h).Count ();

return tempval;
}



    

public static long display()
{
var tempval = (from h in objDB.tbl_mvc_login
select h).LongCount ();

return tempval;
}


Look carefully to the above methods declared. They both does the same thing but LongCount() has a greater range than Count(). According to MSDN, it has the range from

long.MinValue = -9223372036854775808

long.MaxValue = 9223372036854775807


which is quite big. Its DotNet Framework type is System.Int64. While count() DotNet Framework type is System.Int32 which has a range from

long.MinValue = -2,147,483,648

long.MaxValue = 2,147,483,647


So, next time if you want to count something which is quite big then use LongCount() extension method otherwise use Count().


Thanks and Regards
Akiii


Source: MSDN | | Alert Moderator 

Comments or Responses

Login to post response