background image

7.请编程遍历页面上所有 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 ; 

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