programming-examples/c-sharp/Linq/C# Program to Generate Odd Numbers in Parallel using LINQ.cs
2019-11-15 12:59:38 +01:00

322 lines
2.2 KiB
C#

/*
* C# Program to Generate Odd Numbers in Parallel using LINQ
*/
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
IEnumerable<int> oddNums = ((ParallelQuery<int>)ParallelEnumerable.Range(20, 2000))
.Where(x => x % 2 != 0)
.Select(i => i);
foreach (int n in oddNums)
{
Console.WriteLine(n);
}
Console.ReadLine();
}
}
/*
871
1371
1871
373
873
1373
1873
375
875
1375
1875
377
877
1377
1877
379
879
1379
1879
381
881
1381
1881
383
883
1383
1883
385
885
1385
1885
387
887
1387
1887
389
889
1389
1889
391
891
1391
1891
393
893
1393
1893
395
895
1395
1895
397
897
1397
1897
399
899
1399
1899
401
901
1401
1901
403
903
1403
1903
405
905
1405
1905
407
907
1407
1907
409
909
1409
1909
411
911
1411
1911
413
913
1413
1913
415
915
1415
1915
417
917
1417
1917
419
919
1419
1919
421
921
1421
1921
423
923
1423
1923
425
925
1425
1925
427
927
1427
1927
429
929
1429
1929
431
931
1431
1931
433
933
1433
1933
435
935
1435
1935
437
937
1437
1937
439
939
1439
1939
441
941
1441
1941
443
943
1443
1943
445
945
1445
1945
447
947
1447
1947
449
949
1449
1949
451
951
1451
1951
453
953
1453
1953
455
955
1455
1955
457
957
1457
1957
459
959
1459
1959
461
961
1461
1961
463
963
1463
1963
465
965
1465
1965
467
967
1467
1967
469
969
1469
1969
471
971
1471
1971
473
973
1473
1973
475
975
1475
1975
477
977
1477
1977
479
979
1479
1979
481
981
1481
1981
483
983
1483
1983
485
985
1485
1985
487
987
1487
1987
489
989
1489
1989
491
991
1491
1991
493
993
1493
1993
495
995
1495
1995
497
997
1497
1997
499
999
1499
1999
501
1001
1501
2001
503
1003
1503
2003
505
1005
1505
2005
507
1007
1507
2007
509
1009
1509
2009
511
1011
1511
2011
513
1013
1513
2013
515
1015
1515
2015
517
1017
1517
2017
519
1019
1519
2019