if you want to do this all in one like your original code you could do the following as well
using System;
namespace ArrayRandomNumbers
{
class RandomNumbers
{
public static void Main()
{
int[] num = new int[1000];
Random rnd = new Random();
var randList = new List<int>();
var distinctList = new List<int>();
for (int i = 0; i < 1000; i++)
{
num[i] = rnd.Next(1000);
randList.Add(num[i]);
Console.WriteLine(randList[i]);
}
distinctList = randList.Distinct().ToList();
distinctList.Sort();
Console.ReadLine();
distinctList.ForEach(delegate(int s)
{
Console.WriteLine(s.ToString());
});
Console.ReadLine();
}
}
}
Yields the following output reading left to right, a short snippet based on the random numbers generated when I ran this if you write these numbers to a file you will see that the distinctList will have the sorted values as you have expected I am showing the unsorted results use the code and you can see for yourself in the debugger when you inspect at the last Console.ReadLine();
774
452
566
682
814
702
585
371
469
694
241
168
235
763
35
548
158
212
106
297
921
65
280
419
682
42
116
52
212
523
467
777
195
999
316
836
735
742
6
332
647
645
245
622
674
925
692
141
643
84
85
806
663
476
971
709
171
146
999
772
585
532
159
946
227
464
972
235
447
199
813
416
206
773
650
275
819
657
745
757
350
974
409
128
437
661
113
719
28
606
664
588
742
234
747
114
485
299
395
209
953
457
694
443
270
668
599
890
826
695
889
514
401
242
421
610
123
31
508
565
350
253
206
840
535
224
673
971
26
535
789
520
262
535
803
892
280
965
857
769
61
223
892
332
717
149
187
500
812
136
990
454
790
829
858
700
250
854
908
46
995
628
864
291
906
369
251
865
438
529
330
158
173
739
504
127
360
874
122
385
37
173
158
889
544
334
730
433
677
103
641
425
57
810
773
432
358
600
426
348
898
321
61
283
806
832
280
50
324
731
339
376
731
522
9
821
469
974
746
571
638
818
188
334
887
904
100
362
965
71
768
760
448
774
487
715
112
875
83
712
54
679
108
945
764
265
694
534
801
952
963
384
854
854
709
79
133
726
395
901
731
917
84
252
962
579
928
956
35
294
709
594
891
34
517
958
709
242
570
622
209
566
561
13
108
384
905
593
65
407
581
385
479
181
980
136
595
855
983*
foreacheven quicker against the collection and the sorting is done last and done very quickly, also if you are not familiar withRandom numbersread up if you are wanting number to be sorted from 1 to 1000 then there is no need for a sort you could just perform a simple loop