如何在某些条件融化时返回单个值 [英] How to return a single value when certain conditions are melt

查看:64
本文介绍了如何在某些条件融化时返回单个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果提供的值符合以下条件,我想让我的文本框的值为SAVINGS,CURRENTS或OTHERS

SAVINGS从101到165

CURRENT从1到17

其他人从331到345



ie(例如)

i want to make the value of my textbox to be either SAVINGS, CURRENTS or OTHERS if the value supplied meets the following conditions
SAVINGS is from number 101 to 165
CURRENT is from number 1 to 17
others is from number 331 to 345

i.e (For example)

if led_code returns 6, txtAcccountType.Text  should be "CURRENT"
if led_code returns 102 , txtAccountType.Text should be "SAVINGS"
if led_code returns 335, txtAccountType.Text should be "OTHERS"





i老实说不要知道怎么去吧。



i知道下面的代码是非常错误的,但我只想展示它。



我尝试过:





i honestly dont know how to go about it.

i know the code below is very very wrong but i just want to show it all the same.

What I have tried:

protected void btnGetAcctDetails_Click(object sender, EventArgs e)
    {

        
        bankacct = new unityws();
        try
        {
            lblMessage.Text = "";
            Ac = new AcctInfo.AccountInfo();// web service that returns the led_code
            Ac = bankacct.AccountInformation(txtAccountNumber.Text);
            if (Ac.ResponseCode == "00")
            {
                txtClientType.Text = Ac.AcctType.ToString();
                if (txtClientType.Text == "1")
                {
                    txtClientType.Text = "INDV";
                }
                else
                {
                    txtClientType.Text = "CORP";
                }
                txtBranchName.Text = Ac.Branch.ToString();
                txtFullname.Text = Ac.Name.ToString();
                txtAcccountType.Text = Ac.AcctDesc.ToString();

                AcctType = Ac.led_code.ToString(); //it passes the value into AcctType
                if (AcctType == "1" || "2")// 
                {
                    txtAcccountType.Text = "CURRENT";
                }
                else if (AcctType == "101" || "165")
                {
                    txtAcccountType.Text = "SAVINGS";
                }
                else if (AcctType == "331" || "345")
                {
                    txtAcccountType.Text = "OTHERS";
                }
            }
            else
            {
                lblMessage.CssClass = "alert-warning";
                lblMessage.Text = "You have entered an Invalid Account Number";
            }
            
        }
        catch
        {

        }
       

        
    }

推荐答案

首先范围适用于数字而非字符串,因此您需要将文本/字符串转换为数字 int.Parse()

First ranges work on numbers not strings so you need to convert text/strings to number with int.Parse():
int num = int.Parse("101"); // string input





第二如果正确,您需要实施:



Second you need to implement if correctly :

if(num > 101 && num < 165) 
{
   // if evaluates to true
}


这篇关于如何在某些条件融化时返回单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆