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
Group Clause: Advance LINQ Part - 1
Bhuvan Pandey
Jun 21
2016
Code
1.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Explanation
string
str =
"thisistestingfileforthetrainees"
;
var x = from a
in
str
group a by a into g
select g;
foreach
(var item
in
x)
{
Console.WriteLine(item.Key +
"\t"
+ item.Count());
}
This program used to display character and frequency of character from given string.
Explanation
int
[] num =
new
int
[] { 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 6, 2 };
var x = from a
in
num
group a by a into g
select g;
foreach
(var item
in
x)
{
Console.WriteLine(item.Key +
"\t"
+ item.Count());
}
This program used to display number and frequency of number from given array.
Explanation
int
[] num =
new
int
[] { 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 6, 2 };
var x = from a
in
num
group a by a into g
select g;
foreach
(var item
in
x)
{
Console.WriteLine(item.Key +
"\t"
+ item.Sum()+
"\t"
+item.Count());
}
This program used to display number, multiplication of number with number frequency and frequency of number from given array.
Note
Group clause used to create a group of values with key. Key contain unique data and can perform operation on value as getting count operation or getting sum operation etc.
Group Clause
Advance LINQ