c#数据库嵌套语句_C#程序演示嵌套if语句的示例

c#数据库嵌套语句

Like other programming languages, in C# also conditions may be checked within a condition, i.e. nested if-else allows us to check other conditions within if or else block.

像其他编程语言一样,在C#中也可以在条件中检查条件,即, 嵌套的if-else允许我们在if或else块中检查其他条件。

Syntax:

句法:

    if(test_condition1){
	    //code section 1
	    if(test_condition_a){
		    //code section a
    }
    else{
	    //code section b
    }
    }
    else if(test_condition2){
    {
	    //code section 2
    }
    else if(test_condition3){
	    //code section 3
    }
    ...
    else{
	    //else code section
    }

See the syntax above, here we are checking test_condition_a within the test_conditon1 block, if test_condition1 will be true, "code section a" will be executed.

参见上面的语法,这里我们在test_conditon1块中检查test_condition_a ,如果test_condition1为true ,则将执行“代码段a”

嵌套if else语句的C#示例 (C# example for nested if else statement)

Here, we are asking for a character – and check whether it is vowel or consonant, if input character is a valid alphabet

在这里,我们要求输入一个字符-如果输入的字符是有效的字母,请检查它是元音还是辅音

// C# program to demonstrate example of 
// nested if else statement 
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            //input a character and check whether it is vowel or consonant 
            //but before it - check input character is an aplhabet or not
            char ch;
            Console.Write("Enter a character: ");
            ch = Console.ReadLine()[0];

            //check ch is an alphabet or not
            if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')){
                Console.WriteLine("{0} is a valid alphabet", ch);
                //checking for vowel or consonant
                if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' ||
                    ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' ||
                    ch == 'U' || ch == 'u')
                {
                    Console.WriteLine("{0} is a vowel", ch);
                }
                else
                {
                    Console.WriteLine("{0} is a consonant", ch);
                }
            }
            else{
                Console.WriteLine("{0} is not a valid alphabet",ch);
            }
			
            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output

输出量

First run:
Enter a character: X
X is a valid alphabet
X is a consonant

Second run:
Enter a character: u
u is a valid alphabet
u is a vowel

Third run:
Enter a character: $
$ is not a valid alphabet


翻译自: https://www.includehelp.com/dot-net/nested-if-else-statement-example-in-c-sharp.aspx

c#数据库嵌套语句

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值