Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

ternary operator in 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 :: c# run batch file 
Csharp :: asp.net core miniprofiler 
Csharp :: c# calculate sum of list 
Csharp :: how to convert object in string JSON c# 
Csharp :: C# async to sync 
Csharp :: how to set foreground from code wpf 
Csharp :: array object to datatable c# 
Csharp :: unity camera follow with lerp 
Csharp :: how to remove all whitespace from a string in c# 
Csharp :: how get data from json in c# 
Csharp :: c# join strings with comma 
Csharp :: group by ef core 
Csharp :: unity reference textmeshpro 
Csharp :: unity toint 
Csharp :: .net core identity get user id 
Csharp :: static c# 
Csharp :: first person mouse look unity 
Csharp :: what is unity 
Csharp :: Get enum value from string or int 
Csharp :: web page search c# 
Csharp :: primitive types c# 
Csharp :: how to show process time run c# 
Csharp :: c# string right extension 
Csharp :: get appsettings from app.config c# .net core 
Csharp :: c# get distinct values all fields from list 
Csharp :: create new object c# 
Csharp :: c# get all letters 
Csharp :: c# unit test for throwing exception method 
Csharp :: max index array c# 
Csharp :: c# get last array element 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =