top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Generate Odd Numbers in Parallel using LINQ in C#?

0 votes
568 views
How to Generate Odd Numbers in Parallel using LINQ in C#?
posted Jun 5, 2017 by Pooja Bhanout

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

This C# Program Generates Odd Numbers in Parallel using LINQ. Here it Provides a set of methods for querying objects that implement ParallelQuery{TSource} to generate odd numbers in parallel.
Here is source code of the C# Program to Generate Odd Numbers in Parallel using LINQ. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  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();
    }
}

Here is the output of the C# Program:

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
answer Jun 26, 2017 by Shivaranjini
Similar Questions
+2 votes

Develop a C# Windows Form Application that allows users to do all of the following.
Read a List of patient's information from a text file (*.txt), the input text file is selected from the Open File Dialog.
Your program should accept any text file with the following format:
a. The file contains columns with Basic information about patients.
b. Columns may be separated by spaces and/or tabs.
c. The first line in the file is the column header.
d. After the header, each line represents a Patient (name, address, phone#, Bdate, gander ,wheight, height and blood type).
e. Successfully imported patients are displayed on a data grid view in a second form and added to a patient list.

  1. The user will be able to display on The Grid view :
    a) Female patients.
    b) Patients with age<45 year. c) Save Over weighted patients on a text file .  Note: To find over weighted patients you have to calculate the BMI value. BMI=Weight/ (Height*Height). If BMI <18.5 >>>>> under weighted.
    18.5<=BMI<=25 >>>>>>>Normal.
    BMI>25 >>>>>>>>>>>> Over Weighted.
...