0

Ok, so I started with this:

string str = Console.ReadLine();
        string[] strSeparator = new string[] { " " };

But I don't know how to count the occurances. My question is, which is the easiest method? I found something like this:

var result  = str.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
            .GroupBy(r => r)
            .Select(grp => new
                {
                    Word = grp.Key,
                    Count = grp.Count()
                });

But I don't understand who is 'r' or 'grp' and how I declare them. It'll be helpful some advice and examples.

claud
  • 1
  • 3
    This is really just a lack of understanding of what a lambda expression is in C#, I suggest you go read up on them. – DavidG Jun 27 '18 at 10:01
  • [Your one stop shop for answers](https://msdn.microsoft.com/en-us/library/system.linq.enumerable.groupby(v=vs.110).aspx) – TheGeneral Jun 27 '18 at 10:02
  • @AlexK. Tempted to hammer this closed for that, but I wonder if [this](https://stackoverflow.com/questions/167343/c-sharp-lambda-expressions-why-should-i-use-them) is better? – DavidG Jun 27 '18 at 10:03
  • @claud I've closed this as a duplicate showing you how to count words, but your real questions are about lambdas, so see [here](https://stackoverflow.com/questions/167343/c-sharp-lambda-expressions-why-should-i-use-them) for that info. – DavidG Jun 27 '18 at 10:08
  • @DavidG Ok, I will inform. Thanks for answers – claud Jun 27 '18 at 10:10

0 Answers0