c#如何嵌套第三方程序_C#程序演示嵌套条件运算符的示例
c#如何嵌套第三方程序
C# (or other programming languages also) allows to use a conditional/ternary operator within another conditional/ternary operator.
C#(或其他編程語言)還允許在另一個條件/三元運算符中使用條件/三元運算符。
Syntax:
句法:
(logical_test1) ? ((logical_test2)? True_block : false_block) : false_block_outer;If logical_test1 is true then logical_test2 will be checked, if it is true then "true_block" executes, else "false_block" executes, and if logical_test1 is false then "false_block_outer" will be executed.
如果logical_test1為true,則將檢查logical_test2 ,如果為true,則將執行“ true_block” ,否則將執行“ false_block” ,如果logical_test1為false,則將執行“ false_block_outer” 。
Note: Inner conditional operator can be used in any block as per the requirement.
注意:根據條件,可以在任何塊中使用內部條件運算符。
嵌套條件/三元運算符的C#示例 (C# example for nested conditional/ternary operator)
Here, we are asking to input three numbers and finding the largest number.
在這里,我們要求輸入三個數字并找到最大的數字。
// C# program to demonstrate example of // nested conditional operator using System; using System.IO; using System.Text;namespace IncludeHelp {class Test{// Main Method static void Main(string[] args){//finding largest of three numbers int a;int b;int c;//input numbers Console.Write("Enter first number : ");a = Convert.ToInt32(Console.ReadLine());Console.Write("Enter second number: ");b = Convert.ToInt32(Console.ReadLine());Console.Write("Enter third number : ");c = Convert.ToInt32(Console.ReadLine());//finding largest numberint large = (a>b)?((a>c)?a:c):(b>c?b:c);Console.WriteLine("Largest number is {0}", large);//hit ENTER to exit the programConsole.ReadLine();}} }Output
輸出量
First run: Enter first number : 30 Enter second number: 20 Enter third number : 10 Largest number is 30Second run: Enter first number : 10 Enter second number: 30 Enter third number : 20 Largest number is 30Third run: Enter first number : 10 Enter second number: 20 Enter third number : 30 Largest number is 30翻譯自: https://www.includehelp.com/dot-net/nested-conditional-operator-example-in-c-sharp.aspx
c#如何嵌套第三方程序
總結
以上是生活随笔為你收集整理的c#如何嵌套第三方程序_C#程序演示嵌套条件运算符的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java LinkedList公共int
- 下一篇: 数组tostring方法_数组toStr