部分面試題

來源:互聯網
上載者:User

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.請編程實現一個冒泡排序演算法?
答:
        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 ;
}
}
}

3.求以下運算式的值,寫出您想到的一種或幾種實現方法: 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
{
Sum = Sum  - I ;
}
}
System.Console.WriteLine(Sum.ToString());
System.Console.ReadLine() ;

4.用.net做B/S結構的系統,您是用幾層結構來開發,每一層之間的關係以及為什麼要這樣分層?
答:一般為3層
        資料訪問層,業務層,展示層。
        資料訪問層對資料庫進行增刪查改。
        業務層一般分為二層,業務表觀層實現與展示層的溝通,商務規則層實現使用者密碼的安全等。
        展示層為了與使用者互動例如使用者添加表單。
優點:  分工明確,條理清晰,易於調試,而且具有可擴充性。
缺點:  增加成本。

5.在下面的例子裡
     using System;
     class A
     {
          public A()
           {
                PrintFields();
           }
          public virtual void PrintFields(){}
      }
      class B:A
      {
           int x=1;
           int y;
           public B()
   {
               y=-1;
           }
           public override void PrintFields()
           {
               Console.WriteLine("x={0},y={1}",x,y);
           }
當使用new B()建立B的執行個體時,產生什麼輸出?
答:X=1,Y=0;x= 1 y = -1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.