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 :: c# tell if list object is empty 
Csharp :: c# get battery level 
Csharp :: c# merge two xml files 
Csharp :: how to print statement in c# 
Csharp :: c# array of class 
Csharp :: IHttpContextAccessor 
Csharp :: c# remove all punctuation from string 
Csharp :: c# get custom attribute from property 
Csharp :: c# right function 
Csharp :: join array in c# 
Csharp :: c# get process file location 
Csharp :: c# binary search 
Csharp :: upload file using httpwebrequest c# 
Csharp :: from string 
Csharp :: input unity 
Csharp :: C# short getter setter 
Csharp :: bsod screen c# 
Csharp :: emgucv open image c# 
Csharp :: get last index C# 
Csharp :: meaning immutable and mutable 
Csharp :: .net 6 autofac 
Csharp :: c# timer 30 seconds 
Csharp :: unity getcomponent 
Csharp :: C# trim trailing zero 
Csharp :: c# dictionary get key by value 
Csharp :: declare enum c# 
Csharp :: singleton pattern c# 
Csharp :: enum in c# 
Csharp :: c# destroy function...unity 
Csharp :: ultimate space cruiser 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =