Using Same L I N Q Query More Then Once C# with Example



Using Same L I N Q Query More Then Once C# with Example

 using System;
using System.Linq;

namespace CSharpLINQ
{
    class SimpleQuery
    {
        static void Main()
        {
            int[] numbers = { 1, -2, 3, 0, -4, 5, 10,  };

            // Create a query that obtains only positive numbers.
            var posNums = from n in numbers where n > 0 select n;
            
			Console.Write("The positive values in numbers: ");

            // Execute the query and display the results.
            foreach (var i in posNums) Console.Write(i + " ");
			
			// Modifying Data Source 
			numbers[1] = 22;
			numbers[2] = 13;
			
			Console.Write("\nThe positive values in numbers: ");
			// Execute the query again and display the results.
            foreach (var i in posNums) Console.Write(i + " ");
        }
    }
}
 

0 Comment's

Comment Form

Submit Comment