TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
LINQ To SQL: Count operator
Vijai Anand Ramalingam
Jun 20, 2011
5.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog we will be seeing how to count the number of elements in the sequence
EmpDetails Table:
Code:
To count the number of elements in the sequence.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LINQ
{
class
Program
{
static
void
Main(
string
[] args)
{
DataClassesDataContext
dc =
new
DataClassesDataContext
();
int
empCount = (
from
emp
in
dc.EmpDetails
select
emp).Count();
Console
.WriteLine(empCount);
Console
.Read();
}
}
}
Alternate Method:
DataClassesDataContext
dc =
new
DataClassesDataContext
();
int
empCount = dc.EmpDetails.Count();
Console
.WriteLine(empCount);
Next Recommended Reading
LINQ To SQL: Sum operator