为什么非要写成一行呢?如果strBit的值可能有几十个,我觉得写成几十行更明了好看
解决方案 »
- GridView插入CheckBox选中的数据到SQL数据库
- 报表绘制问题,利用位图字节流在报表中显示一张图片
- C# 操作word文件的合并问题。
- 祝大家中秋快乐!散分...
- 关于事件的不解之处
- 如何用C#实现电子邮件中的附件的接收? 在线等!十万火急!
- xml问题,大家帮帮忙。
- 做个拍号程序,从1-2000选出前1000个,号码随机出,但是最好避免最后没有1000以内的号,也就是前1000号出的比较平均点,用什么算法比较好
- 请问DataGrid里的按钮的事件处理程序中无法打开PDF文件的链接怎么办呀?
- 长沙有人有VS.NET D版吗???
- 关闭窗口用Close()好还是Dispose()好?
- 高分求救!!!关于Remoting,如何调用两个远程对象
我肯定分开写 不然 一行看着多类
c#中的switch case语句对应的是vb.net中的select case
用来模拟。简单的重构了一下,如果你实在找不到更好的答案,看看
这个能不能用。
# 其实个人既不喜欢Switch函数的式样,也不提倡使用这样的构成。
# 只是有的时候真的是蛮便利。:P 因为我的代码都是用其它语言做的注释,所以我就都给删掉了。
并且Switch函数的式样与VB的并不相同。如没有参数和不存在符合
条件的情况下,我都throw了一个异常。理由是我确信我不会书写违反
这个规则的代码。如果你在使用上感觉有什么不方便,去掉也无妨? 另外,我还有模拟了Oracle中的Decode函数,不管用不用,反正塞
进去。:P// 类的定义:
using System;namespace StudySwitch
{
public class Switch
{
public static object SwitchVB(params object[] VarExpr)
{
int len = VarExpr.Length; if ( len <= 0 )
{
throw ( new ArgumentException());
} if ( System.Math.IEEERemainder(len,2) != 0 )
{
throw ( new ArgumentException());
} for ( int i = 0; i < len ; i += 2 )
{
if ( VarExpr[i].Equals(true) )
{
return VarExpr[i+1];
}
} throw ( new ArgumentException()); } public static object DecodeOracle(params object[] VarExpr)
{
int len = VarExpr.Length;
bool blnIsDefault = false; if ( len <= 2 )
{
throw ( new ArgumentException());
}
object target = VarExpr[0]; if ( System.Math.IEEERemainder(len,2) == 0 )
{
blnIsDefault = true;
} for ( int i = 1; i < len ; i += 2 )
{
if ( target.Equals(VarExpr[i]) )
{
return VarExpr[i+1];
}
} if ( blnIsDefault == true )
{
return VarExpr[len-1];
}
else
{
throw ( new ArgumentException());
}
}
}
}// 使用方法:
using System;
using StudySwitch;namespace DefaultNamespace
{
class MainClass
{
public static void Main(string[] args)
{
string strTest = "2";
System.Console.WriteLine(
StudySwitch.Switch.SwitchVB(
strTest == "0","hoho",
strTest == "1","heihei",
strTest == "2" ,"hehe")); strTest = "2";
System.Console.WriteLine(
StudySwitch.Switch.DecodeOracle(
strTest,"0","hoho","1","heihei","2","hehe","wawa")); }
}
}