Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Group Clause: Advance LINQ Part - 1
WhatsApp
Bhuvan Pandey
Jun 21
2016
1.3
k
0
0
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
Up Next
Group Clause: Advance LINQ Part - 1