如何按升序排列数组项

时间:2016-10-05 12:16:10

标签: c#

我试图按升序排列这个数组,但我不知道为什么当我运行它时,我得到了我想要的东西。

import React, { Component } from 'react';
import { reduxForm } from 'redux-form';

class Userform extends Component {

  static handleFormSubmit({ id, name}) {
    console.log({id, name});
  }

  render () {
    const { handleSubmit, fields: { id, name }} = this.props;
    return(
      <form onSubmit={handleSubmit(Userform.handleFormSubmit.bind(this))}>
        <fieldset>
          <label>Id:</label>
          <input {...id}/>
        </fieldset>
        <fieldset>
          <label>Name:</label>
          <input {...name} />
        </fieldset>
        <button action="submit">Submit</button>
      </form>
    );
  }
}


export default reduxForm({
  form: 'userform',
  fields: ['id', 'name']
})(Userform);

2 个答案:

答案 0 :(得分:0)

添加Array.Reverse(array);

怎么样?
private static void sort()
        {
            int[] array = new int[3];
            int order = array[0];
            Console.WriteLine("plz enter 3 numbers");
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = int.Parse(Console.ReadLine());

                Array.Sort(array);
                Array.Reverse(array);
                Console.WriteLine("the number in order  ", array[i]);
            }

            Console.ReadKey();
        }

答案 1 :(得分:0)

你需要首先阅读这些数字,然后排序并持续但最重要的是打印它们

private static void sort()
{
    int[] array = new int[3];
    int order = array[0];
    Console.WriteLine("plz enter 3 numbers");
    for (int i = 0; i < array.Length; i++)
    {
        array[i] = int.Parse(Console.ReadLine());
    }
    Array.Sort(array);

    for (int i = 0; i < array.Length; i++)
        Console.WriteLine("the number in order  ", array [i]);
    }

    Console.ReadKey();
  }