A
A
anonymous2017-09-02 15:23:15
.NET
anonymous, 2017-09-02 15:23:15

Why doesn't LINQ work properly?

I just started learning LINQ and sometimes there are difficulties,
why does it output only "sa" and not a string from the first characters of the array of strings?

//4. Дана последовательность непустых строк.Используя метод Aggregate,
            // получить строку, состоящую из на-
            //чальных символов всех строк исходной последовательности. 

            string[] s = new[] { "sgsg", "tdfgsdfg", "rdfgsdfg", "iiutyiu", "4fghdhsfd", "kasdgfdsf", "asdfdfsd" };

            var res = s.Aggregate((a,b) => a.First() + "" + b.First() );

            Console.WriteLine($"{res}");

            Console.ReadLine();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-09-02
@anonymouss

string[] s = new[] { "sgsg", "tdfgsdfg", "rdfgsdfg", "iiutyiu", "4fghdhsfd", "kasdgfdsf", "asdfdfsd" };

var res = "";

res = s.Aggregate(res, (a, b) => a + b[0]);

Console.WriteLine($"{res}");

Console.ReadLine();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question