Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!

Win Prizes

Like us on Facebook
Top Articles Author
Wed, 16-Apr-2014 Authors
All Time Authors
Bharathi Cherukuri

Latest members | More ...

(Statistics delayed by 5 minutes)

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

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


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

Source: MSDN | | Alert Moderator 

Found interesting? Add this to:

Comments or Responses

Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.