如果是C中的statemnet则复杂 [英] Complicated if statemnet in C

查看:93
本文介绍了如果是C中的statemnet则复杂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI伙计们,



我正在做一个用户可以使用组合框,复选框等信息的应用程序



问题是我需要给他们一些客户详细信息取决于他们选择的数据。





我有一个带有5个条件的if语句示例:



if(a> 0,B> 0,c> 0,d> 0,e> 0)



现在这些可以合并,所以我需要做很多if语句(因子5(120语句))





,有人知道如何减少这个if语句的复杂性和重复性。



< br $> b $ b

代码示例:





 / if (this.Mcc.Length> 1&& this.CheckboxIsTicked == false&& this.TestCases> 0&& THIS.TESTCASE1> 0&& THIS.TESTCASE2> 0) 
{

sql =SELECT * FROM TABLE1;


} ELSE IF(< pre> this.Mcc.Length> 1&& this.CheckboxIsTicked == false&& this.TestCases> 0& & THIS.TESTCASE1> 0&& THIS.TESTCASE2< 0



{

sql =SELECT * FROM TABLE2 ;



}





还有很多东西



我尝试了什么:



i试图让它变得更简单,但我做不到。建议请问?

解决方案

查看决策表 - 维基百科 [ ^ ]。


< blockquote>如果你只想要字符串,那么一种方法是设置和数组,并将每个if条件减少到整数中的一个位。

  int  i ndex =  0 ; 
if (a > 0 )index | = 1 ;
如果(b > 0 )index | = 2 ;
if (c > 0 )index | = 4 ;



然后,您可以设置一个与索引值:

  string  [] choices =  new   string  [] { 选择* FROM none 
选择* FROM a only
选择* FROM b only
选择* FROM a和b
选择* FROM c仅
选择* FROM a和c
选择* FROM b和c
选择* FROM a,b和c};

并直接选择你的字符串。


您正在查看的是构建决策表。


HI guys,

I'm doing an application that users can use certain information from combo boxes, checkboxes etc

The problem is that I need to give them some client details depends on the data they chose.


I have an if statement with 5 conditions example:

if(a > 0, B >0, c>0 ,d>0, e>0)

now these can be combined so I need to do a lot of if statement ( factorial of 5 (120 if statements))


, someone know a way how can i reduce the complexity and repetition of this if statement please.



CODE EXAMPLE:


/if (this.Mcc.Length > 1 && this.CheckboxIsTicked == false && this.TestCases > 0 && THIS.TESTCASE1 > 0 && THIS.TESTCASE2 > 0)
                    {
                        
                            sql = "SELECT * FROM  TABLE1;
                       

                    }ELSE IF(<pre>this.Mcc.Length > 1 && this.CheckboxIsTicked == false && this.TestCases > 0 && THIS.TESTCASE1 > 0 && THIS.TESTCASE2 < 0

)
{
sql = "SELECT * FROM TABLE2;

}


AND MANY MANY MORE

What I have tried:

i tried to make it simpler but i cannot. Some suggestions pleasE?

解决方案

Have a look at Decision table - Wikipedia[^].


if you want just strings, then one way to do it is to set up and array, and reduce each if condition to a single bit in an integer.

int index = 0;
if (a > 0) index |= 1;
if (b > 0) index |= 2;
if (c > 0) index |= 4;


You can then set up an array of strings that relates to the index value:

string[] selects = new string[] { "Select * FROM none",
                                  "Select * FROM a only",
                                  "Select * FROM b only",
                                  "Select * FROM a and b",
                                  "Select * FROM c only",
                                  "Select * FROM a and c",
                                  "Select * FROM b and c",
                                  "Select * FROM a, b, and c"};

And select your string directly.


What you are looking at is building a decision table.


这篇关于如果是C中的statemnet则复杂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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