Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

ternary operator c#

Object obj = null
//    is this condition true ? yes : no
var output = (obj == null) ? "Yes" : "No";

// output = "yes"
Comment

c# ternary operator

is this condition true ? yes : no
Comment

ternary operator c#


conditional-expression:
    conditional-or-expression
    conditional-or-expression   ?   expression   :   expression 

Comment

c# ternary operator

static void Sample(string input)
{
    string result = input == null ? "default" : input;
    Console.WriteLine($"Result: {result}");
}
Comment

C# Ternary Operator

using System;
 
namespace Operator
{
	class TernaryOperator
	{
		public static void Main(string[] args)
		{
			int number = 10;
			string result;

			result = (number % 2 == 0)? "Even Number" : "Odd Number";
			Console.WriteLine("{0} is {1}", number, result);
		}
	}
}
Comment

c# ternary operator

double sinc(double x) => x != 0.0 ? Math.Sin(x) / x : 1;

Console.WriteLine(sinc(0.1));
Console.WriteLine(sinc(0.0));
// Output:
// 0.998334166468282
// 1
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity switch to scene and transfer data 
Csharp :: linq foreach c# 
Csharp :: unity getcomponent 
Csharp :: c# draw rectangle on screen 
Csharp :: #ifdef in c 
Csharp :: element click intercepted exception in selenium C# 
Csharp :: C# compare date values 
Csharp :: get device name c# console 
Csharp :: sequelize top 
Csharp :: remove item from list in for loop c# 
Csharp :: unity scroll rect to bottom 
Csharp :: declare enum c# 
Csharp :: unity agent look at 
Csharp :: mysqldump - date 
Csharp :: SieveOfEratosthenes 
Csharp :: unity get max occurrence in list 
Csharp :: c# get a value from value tuple list 
Csharp :: c# make a automapper 
Csharp :: convert string to decimal c# 
Csharp :: c# find element in list of list 
Csharp :: csharp Console.Read(); 
Csharp :: C# Linq item index 
Csharp :: c# record 
Csharp :: asp c# page scroll position change after postback 
Csharp :: translate int to string with x 0 before c# 
Csharp :: int model property shows 0 in textbox .net core 
Csharp :: how to check if a file is running in c# 
Csharp :: web client ignore ssl error 
Csharp :: regex only letters and numbers c# 
Csharp :: c# convert string to array 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =