Answer the question
In order to leave comments, you need to log in
How to concatenate an array of int into 1 string C#?
It is necessary to combine the array of numbers into 1 line by gluing them in order and inserting a '+' symbol between them.
Can this be done without a single line loop using LINQ?
Answer the question
In order to leave comments, you need to log in
// входящие данные
var arr = new int[] { 5, 10, 7, 123, 0 };
// Console.WriteLine(String.Join("+", arr.OrderBy(n => n).Select(n => n.ToString())));
// сортируем
var sorted = arr.OrderBy(n => n);
// склеиваем
Console.WriteLine(String.Join("+", sorted.Select(n => n.ToString())));
// или без вызова ToString(), если используемая версия .NET позволит:
// Console.WriteLine(String.Join("+", sorted));
// или с вызовом ToArray() для ранних версий .NET:
// String.Join("+", sorted.Select(n => n.ToString()).ToArray())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question