.net 面试算法题

 

1.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty


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;
    }
}

 

2. 一列数的规则如下: 1、1、2、3、5、8、13、21、34......  求第30位数是多少, 用递归算法实现。


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); 
        } 
    }

 

3.经典排序—冒泡排序法

  public static void bubble_sort(int[] x)
        {
            for (int i = 0; i < x.Length; i++)
            {
                for (int j = i; j < x.Length; j++)
                {
                    if (x[i] < x[j])    //从大到小排序
                    {
                        int temp;
                        temp = x[i];
                        x[i] = x[j];
                        x[j] = temp;
                    }
                }
            }
        }

 

4.写出一条Sql语句: 取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键,  注意:ID可能不是连续的。)

select top 10 * from A where id not in (select top 30 id from A)

select top 10 * from A where id (select max(id) from (select top 30 id from A )as A)

转载于:https://www.cnblogs.com/Aaxuan/articles/7300942.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>