Do calculation in select statement in CSharp

Description

The following code shows how to do calculation in select statement.

Example


  /* w ww .ja  v  a2 s.  co  m*/
  
  
    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {
        int[] numbers = { 5, 4, 1, 3, 9};
        var numsPlusOne =
            from n in numbers
            select n + 1;

        Console.WriteLine("Numbers + 1:");
        foreach (var i in numsPlusOne) {
            Console.WriteLine(i);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ