悬赏园豆:10
[已解决问题]
解决于 2008-07-15 18:40
<P>1..try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后?<BR>答:会执行,在return前执行。</P>
<P>但是我调试时,是在return后执行的,这是我的调试代码:</P>
<P>YeShu.BLL.Dictionary_Type bll = new YeShu.BLL.Dictionary_Type();<BR> try<BR> {</P>
<P> int i = bll.Add(TextBox1.Text.Trim());<BR> Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "aa", "alert('" + i.ToString() + "')", true);<BR> return 2;<BR> }</P>
<P> finally<BR> {<BR> bll = null;<BR> }</P>
<P>2.<SPAN lang=EN-US style="FONT-SIZE: 10.5pt; COLOR: black; FONT-FAMILY: 新宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">swtich</SPAN><SPAN style="FONT-SIZE: 10.5pt; COLOR: black; FONT-FAMILY: 新宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">是否能作用在<SPAN lang=EN-US>byte</SPAN>上,是否能作用在<SPAN lang=EN-US>long</SPAN>上,是否能作用在<SPAN lang=EN-US>String</SPAN>上<SPAN lang=EN-US>?<BR></SPAN>答:<SPAN lang=EN-US>switch</SPAN>(<SPAN lang=EN-US>expr1</SPAN>)中,<SPAN lang=EN-US>expr1</SPAN>是一个整数表达式。因此传递给<SPAN lang=EN-US> switch </SPAN>和<SPAN lang=EN-US> case </SPAN>语句的参数应该是<SPAN lang=EN-US> int</SPAN>、<SPAN lang=EN-US> short</SPAN>、<SPAN lang=EN-US> char </SPAN>或者<SPAN lang=EN-US> byte</SPAN>。<SPAN lang=EN-US>long,string </SPAN>都不能作用于<SPAN lang=EN-US>swtich</SPAN>。<SPAN lang=EN-US><BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break">但是我测试时long和string都可以,测试代码:</SPAN></SPAN></P>
<P><SPAN style="FONT-SIZE: 10.5pt; COLOR: black; FONT-FAMILY: 新宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN lang=EN-US>private void bb(string str)<BR> {<BR> switch (str)<BR> {<BR> case "1":<BR> Response.Write("aaa1");<BR> break;<BR> case "2":<BR> Response.Write("aaa2");<BR> break;<BR> default:<BR> Response.Write("aaat");<BR> break;<BR> }<BR> }</SPAN></SPAN></P>
<P><SPAN style="FONT-SIZE: 10.5pt; COLOR: black; FONT-FAMILY: 新宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN lang=EN-US>到底是我测试出错了,还是答案是错误的</SPAN></SPAN></P>