I am using this code for displaying result as even or odd instead of true and false here:
Console.WriteLine(" is " + result == true ? "even" : "odd");
Therefore i am using ternary operator , but it is throwing error, some syntax problem is here but i am unable to catching it .
Thanks in Advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationForTesting
{
delegate int Increment(int val);
delegate bool IsEven(int v);
class lambdaExpressions
{
static void Main(string[] args)
{
Increment Incr = count => count + 1;
IsEven isEven = n => n % 2 == 0;
Console.WriteLine("Use incr lambda expression:");
int x = -10;
while (x <= 0)
{
Console.Write(x + " ");
bool result = isEven(x);
Console.WriteLine(" is " + result == true ? "even" : "odd");
x = Incr(x);
}
Try it: