9999999m; string str = String.Format( MyCulture, “My amount = {0:c}”, y ); [.NET(C#)] 写一个HTML页面,实现以下功能,左键点击页面时显示“您好”,右键点击时显示“禁止右键”。并在1秒后自动关闭页面。 <script language=”java script”> function MyClick() { if( event.button == 1 ) { alert( “您好”); } else if(event.button == 2 ) { alert( “禁止右键”); setTimeout( “MyClose(); “, 1000); } } function MyClose() { window.close(); } abc [.NET(C#)] 分析以下代码。 public static void test( string ConnectString ) { System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); conn.ConnectionString = ConnectString; try { conn.Open(); // . } catch( Exception Ex ) { MessageBox.Show( Ex.ToString() ); } finally { if( !conn.State.Equals( ConnectionState.Closed ) ) conn.Close(); } } 问题: 1. 以上代码可以正确使用连接池吗? 答:如果传入的connectionString是正确的格式的话,可以正确使用连接池。 2. 以上代码所使用的异常处理方法,是否所有在test方法内的异常都可以被捕捉并显示出来? 答:不能捕获所有的异常,只能捕获在try块内发生的异常。 [.NET(C#)] 以下是一些C#中的枚举型的定义,其中错误的用法有(B) A. public enum var1{ Mike = 100, Nike = 102, Jike } B. public enum var1{ Mike = “1”, Nike, Jike } C. public enum var1{ Mike=-1 , Nike, Jike } D. public enum var1{ Mike , Nike , Jike } [.NET(C#)] 下面的例子中 class A { public static int X; static A() { X = B.Y + 1; } } class B { public static int Y = A.X + 1; static B() { } static void Main() { Console.WriteLine( “X={0},Y={1}”, A.X, B.Y ); } } 产生的输出结果是什么? 答:x=1,y=2 [.NET(C#)] 写出程序的输出结果 class Class1 { private string str = “Class1.str”; private int i = 0; static void StringConvert( string str ) { str = “string being converted.”; } static void StringConvert( Class1 c ) { c.str = “string being converted.”; } static void Add( int i ) { i++; } static void AddWithRef( ref int i ) { i++; } static void Main() { int i1 = 10; int i2 = 20; string str = “str”; Class1 c = new Class1(); Add( i1 ); AddWithRef( ref i2 ); Add( c.i ); StringConvert( str ); StringConvert( c ); Console.WriteLine( i1 ); Console.WriteLine( i2 ); Console.WriteLine( c.i ); Console.WriteLine( str ); Console.WriteLine( c.str ); } } 答案:10, 21, 0, str, string being converted 注意:此处加逗号“,”是为了答案看起来清晰,实际结果是纵向排列的,因为调用了Console.WriteLine()。 [.NET(C#)] 写出程序的输出结果 public abstract class A { public A() { Console.WriteLine( ‘A’ ); } public virtual void Fun() { Console.WriteLine( “A.Fun()” ); } } public class B : A { public B() { Console.WriteLine( ‘B’ ); } public new void Fun() { Console.WriteLine( “B.Fun()” ); } public static void Main() { A a = new B(); a.Fun(); } } 答案: A B A.Fun()
|