Conditional operator and Math calculation : Operators « Language Basics « C# / C Sharp






Conditional operator and Math calculation

 
using System;
class ConditionalOp
{
    static double sinc(double x)
    {
        return x != 0.0 ? Math.Sin(x) / x : 1.0;
    }

    static void Main()
    {
        Console.WriteLine(sinc(0.2));
        Console.WriteLine(sinc(0.1));
        Console.WriteLine(sinc(0.0));
    }
}

   
  








Related examples in the same category

1.The + Operator Is Left Associative
2.Math Operators with int value
3.Demonstrate the difference between prefix postfix forms of ++Demonstrate the difference between prefix 
   postfix forms of ++
4.Demonstrate the relational and logical operatorsDemonstrate the relational and logical operators
5.Demonstrate the short-circuit operatorsDemonstrate the short-circuit operators
6.Side-effects can be importantSide-effects can be important
7.Prevent a division by zero using the ? 1Prevent a division by zero using the ? 1
8.Self incrementSelf increment
9.Self decreaseSelf decrease
10.Illustrates the use of the comparison operatorsIllustrates the use of the comparison operators
11.Illustrates the use of the Boolean logical operatorsIllustrates the use of the Boolean logical operators
12.Ternary operatorTernary operator
13.Illustrates the use of the ternary operatorIllustrates the use of the ternary operator
14.Illustrates the use of the arithmetic operatorsIllustrates the use of the arithmetic operators
15.Illustrates the use of the bitwise operatorsIllustrates the use of the bitwise operators
16.Illustrates the use of the shortcut operatorsIllustrates the use of the shortcut operators
17.Prefix and postfix versions of the increment and decrement operatorsPrefix and postfix versions of the increment and decrement operators
18.Operator precedenceOperator precedence
19.Demonstrates compound assignment operatorsDemonstrates compound assignment operators
20.Relational Operators 3
21.Numeric Operators 3
22.Numeric Operators 1
23.Relational Operators
24.control the operator evaluation sequence
25.'logical and' and bitwise and
26.logical or and bitwise or
27.And Assignment
28.Or Assignment
29.Iff operator in C#
30.logical exclusive-or
31.Add Assigment for both number and string value