Saturday, 2 December 2017

C# Program to Implement Let Condition using LINQ


Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    class Student
    {
        public string Name { get; set; }
        public string Regno { get; set; }
        public int Marks { get; set; }

    }
    class Program
    {
        static void Main(string[] args)
        {
            //Object Initialization for Student class
            List objStudent = new List{
                    new Student{ Name="Tom",Regno="R001",Marks=80},
                    new Student{ Name="Bob",Regno="R002",Marks=40},
                    new Student{ Name="jerry",Regno="R003",Marks=25},
                    new Student{ Name="Syed",Regno="R004",Marks=30},
                    new Student{ Name="Mob",Regno="R005",Marks=70},
                };

            var objresult = from stu in objStudent
                            let totalMarks = objStudent.Sum(mark => mark.Marks)
                            let avgMarks = totalMarks / 5
                            where avgMarks > stu.Marks
                            select stu;
            foreach (var stu in objresult)
            {
                Console.WriteLine("Student: {0} {1}", stu.Name, stu.Regno);

            }
            Console.ReadLine();
        }
    }


Output:

Student: Bob R002
Student: jerry R003
Student: Syed R004


More C# Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...