1.Difference
between First() and Single() extension methods in LINQ
-
S.No First() Single() 1 There is at least one result, an exception is thrown if no result is returned.There is exactly 1 result, no more, no less, an exception is thrown if no result is returned.
-
S.NoFirstOrDefault()SingleOrDefault()
1 It gets the first item that matches a given criteria.If we specify this extension method that means we are specifically saying that there can be only one value that matches the criteria. If there are more then 1 value that matches the criteria, throw an exception.
-
S.No Count() LongCount() 1 Count() has a lesser range than LongCount()long.MinValue = -2,147,483,648long.MaxValue = 2,147,483,647LongCount() has a greater range than Count().long.MinValue = -9223372036854775808long.MaxValue = 92233720368547758072 Its DotNet Framework type is System.Int32Its DotNet Framework type is System.Int64
Example
for Count():
public
static long display()
{
var tempval = (from h in objDB.tbl_mvc_login
select h).Count ();
return tempval;
}
{
var tempval = (from h in objDB.tbl_mvc_login
select h).Count ();
return tempval;
}
Example
for LongCount():
public
static long display()
{
var tempval = (from h in objDB.tbl_mvc_login
select h).LongCount ();
return tempval;
}
{
var tempval = (from h in objDB.tbl_mvc_login
select h).LongCount ();
return tempval;
}
Summary:
They
both does the same thing .If we want to count something which is
quite big then we have to use LongCount() extension method otherwise
we can use Count().
No comments:
Post a Comment