background image

                

if

 (objControl 

is

 System.Web.UI.WebControls.TextBox)

                {
                    ((TextBox)objControl).Text = String.Empty;
                   }
               }
           }
       }
8.请编程实现一个冒泡排序算法?
答:

class

 

Program

    {
        

static

 

void

 Main(

string

[] args)

        {
            

int

[] str = { 12, 5, 21, 45, 9, 5, 48, 15, 59, 78 };

            

int

 temp = 0;

            

for

 (

int

 i = 0; i < str.Length-1;i++ )

            {
                

for

 (

int

 j = i + 1; j < str.Length; j++) 

                {
                    

if

 (str[i] < str[j])

                    {
                        temp = str[i];
                        str[i] = str[j];
                        str[j] = temp;
                    }
                }
            }
            

foreach

(

int

 x 

in

 str)

            {
                

Console

.WriteLine(x);

            }
                

Console

.ReadKey();

            
        }
}
9.描述一下 C#中索引器的实现过程,是否只能根据数字进行索引?
答:所谓索引器就是一类特殊的属性,通过他们你就像引用数组一样引用自己的类。类里
定义的每一个索引器必须拥有唯一的标签或参数列表;索引器必须是实例成员;为索引
器定义的访问函数可以访问传递给索引器的参数。
<modifier> <return type> this [argument list]
...{
get
...{
// Get codes goes here