0
using System;
using System.Linq;
using System.Collections.Generic;

namespace практика1
{
    struct Sportsmen
    {
        private string famile;
        private double rez;

        public string Famile { get { return famile; } set { famile = value; } }
        public double Rez { get { return rez; } set { rez = value; } }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Sportsmen[] temp = new Sportsmen[5];
            string[] arr = new string[5] { "Иванов", "Sidorov", "Petrov", "Amongusov", "Susov" };
            double[] rez = new double[5] { 3.4, 6.2, 7.3, 9.1, 6.6 };

            for (int i = 0; i < temp.Length; i++)
            {
                temp[i].Famile = arr[i];
                temp[i].Rez = rez[i];
                Console.WriteLine("Фam {0} \t Res {1:f2}", temp[i].Famile, temp[i].Rez);
            }

            temp.OrderBy(p => p.Rez);

            for (int i = 0; i < temp.Length; i++)
            {
                Console.WriteLine("Фam {0} \t Res {1:f2}", temp[i].Famile, temp[i].Rez);
            }
        }
    }
}

После temp.OrderBy(p => p.Rez); ничего не меняется

2
  • 1
    OrderBy возвращает результат. Его нужно чему-то присвоить. 28 фев 2023 в 18:06
  • Sportsmen[] sportsmens = temp.OrderBy(p => p.Rez); выдает ошибку CS0029: Cannot implicitly convert type 'type' to 'type'
    – artzsh
    28 фев 2023 в 18:12

1 ответ 1

0

Нужно присвоить результат переменной. Так же не стоит забывать про ToArray, потому что OrderBy возвращает не Sportsmen[], а IOrderedEnumerable

Sportsmen[] sportsmens = temp.OrderBy(p => p.Rez).ToArray()

https://learn.microsoft.com/ru-ru/dotnet/api/system.linq.enumerable.orderby?view=net-7.0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.