public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static int Foo(int i) { if (i <= 0) return 0; else if (i > 0 && i <= 2) return 1; else return Foo(i - 1) + Foo(i - 2); } }
foreach (System.Windows.Forms.Control control in this.Controls) { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control; tb.Text = String.Empty ; } }
8. 请编程实现一个冒泡排序算法? 答:
int [] array = new int; int temp = 0 ; for (int i = 0 ; i < array.Length - 1 ; i++) { for (int j = i + 1 ; j < array.Length ; j++) { if (array[j] < array[i]) { temp = array[i]; array[i] = array[j]; array[j] = temp ; } } }
9. 描述一下C#中索引器的实现过程,是否只能根据数字进行索引? 答:不是。可以用任意类型。
10. 求以下表达式的值,写出您想到的一种或几种实现方法:1-2+3-4+……+m 答:
int Num = this.TextBox1.Text.ToString(); int Sum = 0; for (int i = 0; i < Num + 1; i++) { if ((i % 2) == 1) { Sum += i; } else { Sum = Sum - I; } } System.Console.WriteLine(Sum.ToString()); System.Console.ReadLine();
namespace test { public delegate void OnDBOperate(); public class UserControlBase : System.Windows.Forms.UserControl { public event OnDBOperate OnNew; privatevoidtoolBar_ButtonClick(objectsender,System.Windows.Forms.ToolBarButtonClickEventArgs e) { if(e.Button.Equals(BtnNew)) { //请在以下补齐代码用来调用OnDBOperate委托签名的OnNew事件。 } } } } 答:if( OnNew != null ) OnNew(this, e);
27. 分析以下代码,完成填空 string strTmp = "abcdefg某某某"; int i= System.Text.Encoding.Default.GetBytes(strTmp).Length; int j= strTmp.Length; 以上代码执行完后,i=______ j=______ 答:i=13,j=10
28. SQLSERVER服务器中,给定表 table1 中有两个字段 ID、LastUpdateDate,ID表示更新的事务号,LastUpdateDate表示更新时的服务器时间,请使用一句SQL语句获得最后更新的事务号 答:Select ID FROM table1 Where LastUpdateDate = (Select MAX(LastUpdateDate) FROM table1)
void FindFile( Directory d ) { FileOrFolders = d.GetFileOrFolders(); foreach( FileOrFolder fof in FileOrFolders ) { if( fof is File ) You Found a file; else if ( fof is Directory ) FindFile( fof ); } }
33. 写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的。 答:解1: select top 10 * from A where id not in (select top 30 id from A) 解2: select top 10 * from A where id > (select max(id) from (select top 30 id from A )as A)