Language Integrated Query (LINQ) Question:

Write a program using LINQ to find the sum of first 5 prime numbers?

Tweet Share WhatsApp

Answer:

class Program
{
static void Main()
{
int[] MyPrimeNumbers = {1,2,3,5,7};
// Use the Count() and Sum() Standard Query Operators to
// compute the count and total sum respectively
Concole.WriteLine("The sum of first {0} prime number is {1}",
MyPrimeNumbers.Count(), MyPrimeNumbers.Sum());
}
}

Download LINQ PDF Read All 35 LINQ Questions
Previous QuestionNext Question
What are the four LINQ Providers that .NET Framework ships?What is Difference between XElement and XDocument?