递归算法运用

一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少,

public class MainClass

{

public staticvoid Main()

{

      Console.WriteLine(Foo());

}

public staticint Foo(int i)

{

      if(i <= )

            return0;

      elseif(i >  && i <= )

            return1;

      elsereturn Foo(i -) + Foo(i - );

}

}

页面上所有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 ;

      }

}

冒泡排序算法

int [] array =new int ;

int temp =  ;

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

{

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

      {

            if(array[j] < array[i])

            {

                  temp= array[i] ;

                  array[i]= array[j] ;

                  array[j]= temp ;

            }

      }

}

分析程序输出

1、当使用new B()创建B的实例时,产生什么输出?

using System;

class A

{

      publicA()

      {

            PrintFields();

      }

      publicvirtual void PrintFields(){}

}

class B:A

{

      intx=;

      inty;

      publicB()

      {

            y=-;

      }

      publicoverride void PrintFields()

      {

            Console.WriteLine("x={0},y={1}",x,y);

      }

}

答:X=1,Y=0;

2、以下代码输出:

using System;

class A

{

      public static int X;

      static A()

      {

            X=B.Y+;

      }

}

class B

{

      public static int Y=A.X+;

      static B(){}

      static void Main()

      {

            Console.WriteLine("X={0},Y={1}",A.X,B.Y);

      }

}

答:x=1,y=2

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

采用list和循环

int[] intArr=new int[];

ArrayList myList=new ArrayList();

Random rnd=new Random();

while(myList.Count<)

{

      int num=rnd.Next(,);

      if(!myList.Contains(num))     

      myList.Add(num);

}

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

      intArr[i]=(int)myList[i];

最新文章

  1. require的总结
  2. android——从零开始
  3. pdfkit安装使用
  4. C#的cs文件中Response.Clear();Response.ClearHeaders()的作用
  5. [Papers]NSE, $\pi$, Lorentz space [Suzuki, NA, 2012]
  6. 一个js排序
  7. PHPCMS v9栏目添加字段及描述编辑器修改方法
  8. wxWidgets Tutorial
  9. Akka(38): Http:Entityof ByteString-数据传输基础
  10. Java编程思想阅读收获
  11. excel冻结标题栏,让标题栏不滚动的方法
  12. 使用LVM进行分区扩展的记录
  13. 【转载】ASP.NET生成图片的缩略图
  14. SolrCloud集群搭建(基于zookeeper)
  15. 根据设备宽高设置View的大小
  16. 禁止网站被别人通过iframe引用
  17. LINUX系统一一CentOS6.5之tomcat安装
  18. OpenGL笔记(四) API参考
  19. spring整合redis(jedis)
  20. the django travel three[form表单验证]

热门文章

  1. shell自动化一键部署脚本,秒级一键回滚脚本
  2. APPIUM API整理(python)---其他辅助类
  3. NOIP 转圈游戏
  4. 使用Kali Linux 破解无线网
  5. 无网络环境用pip安装python类包
  6. HUE中oozie执行shell
  7. tomcat绿色版——运行一闪而过的解决方法
  8. linux rpm 卸载,简单说明
  9. RabbitMQ C# driver stops receiving messages
  10. CSS自定义字体(@font-face选择符)