有一個放了N個數的List,現在要找前三名,List已經按降序排序,在正常情況下前三個數就是前三名,但也會出現并排情況。那么現在想用三個List或者數組裝著這三個名次的數,想問怎樣做更效率`大家懂的能不能詳細說下``謝謝了

解决方案 »

  1.   

    List<int> list2 =  list.Take(3);//前三名
    Array[] list2 =  list.Take(3).ToArray();//数组接收前三名
      

  2.   

    list//已排好序
    Int32 [] arr = new Int32[3];
    arr[0] = list[0];
    Int32 index = 1;
    for(Int32 i = 1;i < list.Count;i++)
    {
       if(list[i] != arr[index - 1])
       {
         arr[index] = list[i];
         index++;
         if(index >= 3)
           break;
       }
    }
      

  3.   

    int n = 3;
                int mm = 0;
                for (int i = 0; i < Array.Length-1; i++)
                {
                    if (mm < 2)
                    {
                        if (int_Array[i] == int_Array[i + 1])
                            n++;
                        else
                            mm++;
                    }
                    
                }
                for (int i = 0; i < n; i++)
                {
                    Console.Write(int_Array[i].ToString());
                }
                Console.ReadLine();
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Collections;
    using System.Xml.Linq;namespace ConsoleCSharp
    {
        class Program
        {        static void Main(string[] args)
            {
                List<int> lintint = new List<int>
                {1,2,1,2,3,4,5,4,5,6,7
                };
                lintint.Sort(delegate(int a, int b)
                {
                    return b - a;
                });
                IEnumerable<int> ll = lintint.Distinct().Take(3);
                foreach (var item in ll)
                {
                    Console.WriteLine(item);
                }        }
        }
    }