点滴积累【other】---.net程序员面试题总结

自己总结的.net的面试题。

说明:以下代码均已经过验证正确无误!

C#:

1.c#实现N的阶乘:

class Program

    {

        static void Main(string[] args)

        {

            int n = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(jiechengN(n));

            Console.ReadKey();

        }

        public static double jiechengN(int n)

        {

            if (n == 1)

            {

                return 1;

            }

            else

            {

                return n * jiechengN(n - 1);

            }

        }

}

2.求一下表达式的值:1-2+3-4+5….+m

       int m = 50;

            int count = 0;

            for (int i; i <= m; i++)

            {

                if (i % 2 == 1)

                {

                    count += i;

                }

                else

                {

                    count -= i;

                }

            }

3.产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复。

       int[] intarr = new int[100];

          ArrayList mylist = new ArrayList();

            Random rdm = new Random();

            while (mylist.Count < 100)

            {

                int num = rdm.Next(1, 101);

                if (!mylist.Contains(num))

                    mylist.Add(num);

            }

            for (int i = 0; i < 100; i++)

            {

                intarr[i] = (int)mylist[i];

            }

4.一列数的规则如下: 112358132134......  求第30位数是多少, 用递归算法实现。

static void Main(string[] args)

        {

            Console.WriteLine(qiu30(30));

            Console.ReadKey();

        }

        public static int qiu30(int i)

        {

            if (i <= 2)

            {

                return 1;

            }

            else

            {

                return qiu30(i - 1) + qiu30(i - 2);

            }

        }

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

Foreach(system.windows.forms.control cont in this.Controls)

{

    If(cont is system.windows.forms.textbox)

    {

        System.windows.form.textbox tb=system.windows.form.textbox(cont);

        Tb.text=string.empty;

    }

}

6.冒泡排序

static void Main(string[] args)

        {

            //int num=6;

            int[] array= new int[6];

            for (int i = 0; i < 6; i++)

            {

                array[i] = Convert.ToInt32(Console.ReadLine());

            }

            maopao(array);

            for (int n = 0; n < array.Length; n++)

            {

                Console.WriteLine(array[n]);

            }

            Console.ReadKey();

        }

        public static void maopao(int[] array)

        {

            for (int i = 0; i < array.Length - 1; i++)

            {

                for (int j = 0; j < array.Length - i - 1; j++)

                {

                    if (array[j] < array[j + 1])

                    {

                        int temp = array[j];

                        array[j] = array[j + 1];

                        array[j + 1] = temp;

                    }

                }

            }

        }

 

SQL:

1.计算及格率:

select name,convert(varchar(10),round(SUM(case when score >=60 then 1 else null end)*100/COUNT(*),2))+ '%' as 及格率 from Class group by Name

2.查询出来 再插入

insert into Class (Name,Score) select class_id,num from score

3. 写出一条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 ( select top 10 * from (select top 40 * from A order by ID) t order by ID desc) s order by id asc

4.查询学生姓名,并且查询分数,当分数大于等于90时显示为优,当分数大于等于80且小于90时显示为良,当分数大于等于60且小于80时显示为中,当分数小于60时显示为差。

select name,(case when score>=90 then '' when score between 80 and 89  then ''  when score between 60 and 79 then '' else '' end) as 成绩 from class

5. left join right join inner join 区别

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行

6. sql 查询表中姓名重复的数据

select name from class group by name having COUNT(name)>1

7. SQL行转列

select * from Class

点滴积累【other】---.net程序员面试题总结

转换后:

select name,SUM(case classname when '语文' then score else 0 end) as 语文,

SUM(case classname when '英语' then score else 0 end) as 英语,

SUM(case classname when '数学' then score else 0 end) as 数学

from Class group by Name

点滴积累【other】---.net程序员面试题总结

 

JQuery:

1.把所有 p 元素的背景颜色更改为红色

$("p").css("background-color","red");

2.Jquery实现全选和取消

<input type='checkbox' id='id1' name='checkname[]' value='1' />value1    

<input type='checkbox' id='id2' name='checkname[]' value='2' />value2   

<input type='checkbox' id='id3' name='checkname[]' value='3' />value3   

    

<input type="button" id="checkall" name="checkall" value="全选" />   

<input type="button" id="delcheckall" name="delcheckall" value="取消全选" />  



$(“#checkalll”).click(

        Function(){

            If(this.checked)

{

    $(“input[name=’checkname’]”).attr(‘checked’,true)

}

Else

{

    $(“input[name=’checkname’]”).attr(‘checked’,false)

}

}

);

3.判断radioselelctcheckbox是否选中

Var  radioVal=$(‘input:radio[name=”sex”]:checked’).val();

If(radioVal ==null)

{

        Alert(“没有选择”);

        Return false;

}

Else

{

        Alert(“已选中);

}



Var selectVal=$(‘select[name=selectID]’).val();



If($(“#checkbox1”).is(“:checked”))

 

你可能感兴趣的:(.net)