Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Wed, 23-Jul-2014 Authors
All Time Authors
Vishal@Neeraj
28480
Rajkatie
20600
Bharathi Cherukuri
18040

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: 2497 | 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 

Found interesting? Add this to:



Comments or Responses

Login to post response