• <nav id="cwumo"><code id="cwumo"></code></nav>
  • <menu id="cwumo"><strong id="cwumo"></strong></menu>

    新蛋科技.net工程方面的筆試題

    時間:2022-10-26 23:04:56 筆試題目 我要投稿
    • 相關推薦

    新蛋科技.net工程方面的筆試題

      1、 DataSet和DataReader的區別和相同點,分別適合用于什么樣的情況?

    新蛋科技.net工程方面的筆試題

      答:

      2、 有基類如下:

      public class parent

      {

      public parent()

      {

      Console.Write(“Parent”);

      }

      }

      請寫出一個子類Son,要求子類的構造函數實現如下的功能:(1)輸出兒子的NAME、SEX、AGE、以及Parent,(2)要求在Son的構造函數里不能有任何的命令語句出現。

      public class parent

      {

      public parent()

      {

      Console.Write(“Parent”);

      }

      }

      public class Son:parent

      { static string name=null;

      static int sex=0;

      static int age=0;

      public parent(string name,int sex,int age):base()

      {

      name=name;

      sex=sex;

      age=age;

      display();

      }

      publci void display()

      {

      Console.WriteLine(“name=”+name);

      Console.WriteLine(“sex=”+sex);

      Console.WriteLine(“age=”+age);

      }

      }

      3、 請例舉出三種以上進行頁面重定向的方式(包括服務端和客戶端)。

      答: 第一種: Response.Redirect,

      第二種: Server.Transfer

      第三種:

      function redirect(url) {

      document.theForm.action = url;

      document.theForm.submit();

      }

      第四種: StringBuilder sb=new StringBuilder();

      sb.Append(“ ”);

      Response.Write(sb.ToString());

      4、 寫出禁用ViewState的語句。

      答: Control(具體的某個控件).EnableViewState=false;

      5、 請談一談.NET的code-behind模式和code_clude模式的區別,和各自的優點及缺點。

      6、 寫出下列七個程序段的輸出結果:

      (1)

      interface InFace

      {

      void fun();

      }

      class MyParent:InFace

      {

      public void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      }

      }

      結果:Parent

      (2)

      interface InFace

      {

      void fun();

      }

      class MyParent:InFace

      {

      public new void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      Console.Read();

      }

      }

      結果:Parent

      (3)

      interface InFace

      {

      void fun();

      }

      class MyParent:InFace

      {

      public new void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public new void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      Console.Read();

      }

      }

      結果:Parent

      (4)

      interface InFace

      {

      void fun();

      }

      class MyParent:InFace

      {

      public void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public override void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      Console.Read();

      }

      }

      結果:語法錯誤: 無法重寫繼承成員“ConsoleApplication6.MyParent.fun()”,因為它未標記為 virtual、abstract 或 override

      (5)

      interface InFace

      {

      void fun();

      }

      abstract class MyParent:InFace

      {

      public virtual void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public override void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      Console.Read();

      }

      }

      結果:Son

      (6)

      interface InFace

      {

      void fun();

      }

      class MyParent:InFace

      {

      public virtual void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public override void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      Console.Read();

      }

      }

      結果:Son

      (7)

      interface InFace

      {

      void fun();

      }

      abstract class MyParent:InFace

      {

      public void fun()

      {

      Console.WriteLine(“Parent”);

      }

      }

      class MySon:MyParent

      {

      public override void fun()

      {

      Console.WriteLine(“Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      InFace inf=new MySon();

      inf.fun();

      Console.Read();

      }

      }

      結果:語法錯誤: 無法重寫繼承成員“ConsoleApplication6.MyParent.fun()”,因為它未標記為 virtual、abstract 或 override

      8、在.NET中有自動的垃圾回收機制,但是我們也可以顯示聲明類的析構函數,請寫出下列程序的輸出結果:像這個程序一樣我們顯示聲明類的析構函數,會有什么問題出現?

      class Parent

      {

      public Parent()

      {

      Console.WriteLine(“Parent”);

      }

      ~Parent()

      {

      Console.WriteLine(“Delete Parent”);

      }

      }

      class Son:Parent

      {

      public Son():base()

      {

      Console.WriteLine(“Son”);

      }

      ~Son()

      {

      Console.WriteLine(“Delete Son”);

      }

      }

      public class MyTest

      {

      public static void Main(string[] args)

      {

      Son son=new Son();

      }

      }

      結果:Parent

      Son

      Delete Son

      Delete Parent

      9、 按值傳遞和按引用傳遞各有什么特點。它們有什么區別?

      答:在按值傳遞中,在被調方法中對變量所做的修改不會影響主調方法中的變量。

      在按引用傳遞中,在被調方法中對變量所做的修改會反映到主調方法中的變量。

      10、 寫出下更程序的輸出結果:

      (1)public class MyTest

      {

      public static void Main(string[] args)

      {

      int i=10;

      fun(i);

      Console.WriteLine(“i=”+i);

      Console.Read();

      }

      public static int fun(int a)

      {

      a++;

      Console.WriteLine(“a=”+a);

      return a;

      }

      }

      結果:a=11

      i=10

      (2)

      public static void Main(string[] args)

      {

      int i=10;

      fun(out i);

      Console.WriteLine(“i=”+i);

      Console.Read();

      }

      public static int fun(out int a)

      {

      a++;

      Console.WriteLine(“a=”+a);

      return a;

      }

      結果:語法錯誤: 控制離開當前方法之前必須對輸出參數“a”賦值

      使用了未賦值的局部變量“a”

      (3)

      public class MyTest

      {

      public static void Main(string[] args)

      {

      int i=10;

      fun(out i);

      Console.WriteLine(“i=”+i);

      Console.Read();

      }

      public static int fun(out int a)

      {

      a=12;

      a++;

      Console.WriteLine(“a=”+a);

      return a;

      }

      }

      結果:a=13

      i=13

      (5)

      public class MyTest

      {

      public static void Main(string[] args)

      {

      int i=10;

      fun(ref i);

      Console.WriteLine(“i=”+i);

      Console.Read();

      }

      public static int fun(ref int a)

      {

      a++;

      Console.WriteLine(“a=”+a);

      return a;

      }

      }

      結果:a=11

      i=11

      附關于out參數的相關知識點:

      必須被賦值。

      方法參數上的 out 方法參數關鍵字使方法引用傳遞到方法的同一個變量。當控制傳遞回調用方法時,在方法中對參數所做的任何更改都將反映在該變量中。

      當希望方法返回多個值時,聲明 out 方法非常有用。使用 out 參數的方法仍然可以返回一個值。一個方法可以有一個以上的 out 參數。

      若要使用 out 參數,必須將參數作為 out 參數顯式傳遞到方法。out 參數的值不會傳遞到 out 參數。

      不必初始化作為 out 參數傳遞的變量。然而,必須在方法返回之前為 out 參數賦值。

      屬性不是變量,不能作為 out 參數傳遞。

      如果兩個方法的聲明僅在 out 的使用方面不同,則會發生重載。不過,無法定義僅在 ref 和 out 方面不同的重載。例如,以下重載聲明是有效的:

      class MyClass

      {

      public void MyMethod(int i) {i = 10;}

      public void MyMethod(out int i) {i = 10;}

      }

      而以下重載聲明是無效的:

      class MyClass

      {

      public void MyMethod(out int i) {i = 10;}

      public void MyMethod(ref int i) {i = 10;}

      }

      與所有的 out 參數一樣,在使用數組類型的 out 參數前必須先為其賦值,即必須由接受方為其賦值。例如:

      public static void MyMethod(out int[] arr)

      {

      arr = new int[10]; // definite assignment of arr

      }

      與所有的 ref 參數一樣,數組類型的 ref 參數必須由調用方明確賦值。因此不需要由接受方明確賦值。可以將數組類型的 ref 參數更改為調用的結果。例如,可以為數組賦以 null 值,或將其初始化為另一個數組。例如:

      public static void MyMethod(ref int[] arr)

      {

      arr = new int[10]; // arr initialized to a different array

      }

      下面的兩個示例說明 out 和 ref 在將數組傳遞給方法上的用法差異。

      示例 1

      在此例中,在調用方(Main 方法)中聲明數組 myArray,并在 FillArray 方法中初始化此數組。然后將數組元素返回調用方并顯示。

      // cs_array_ref_and_out.cs

      using System;

      class TestOut

      {

      static public void FillArray(out int[] myArray)

      {

      // Initialize the array:

      myArray = new int[5] {1, 2, 3, 4, 5};

      }

      static public void Main()

      {

      int[] myArray; // Initialization is not required

      // Pass the array to the callee using out:

      FillArray(out myArray);

      // Display the array elements:

      Console.WriteLine(“Array elements are:”);

      for (int i=0; i < myArray.Length; i++)

      Console.WriteLine(myArray[i]);

      }

      }

      輸出

      Array elements are:

      1

      2

      3

      4

      5

      示例 2

      在此例中,在調用方(Main 方法)中初始化數組 myArray,并通過使用 ref 參數將其傳遞給 FillArray 方法。在 FillArray 方法中更新某些數組元素。然后將數組元素返回調用方并顯示。

      // cs_array_ref_and_out2.cs

      using System;

      class TestRef

      {

      public static void FillArray(ref int[] arr)

      {

      // Create the array on demand:

      if (arr == null)

      arr = new int[10];

      // Otherwise fill the array:

      arr[0] = 123;

      arr[4] = 1024;

      }

      static public void Main ()

      {

      // Initialize the array:

      int[] myArray = {1,2,3,4,5};

      // Pass the array using ref:

      FillArray(ref myArray);

      // Display the updated array:

      Console.WriteLine(“Array elements are:”);

      for (int i = 0; i < myArray.Length; i++)

      Console.WriteLine(myArray[i]);

      }

      }

      輸出

      Array elements are:

      123

      2

      3

      4

      1024

      10、 怎樣從彈出窗口中刷新主窗口?

      private void button1_Click(object sender, System.EventArgs e)

      {

      Form2 frm = new Form2();

      try

      {

      frm.ShowDialog(this);

      }

      finally

      {

      frm.Dispose();

      }

      }

      private void button1_Click(object sender, System.EventArgs e)

      {

      Form parent = this.Owner as Form;

      if(parent != null)

      parent.Refresh();

      }

      11、 Attribute的參數?

      答:Attribute類的構造函數沒有參數,

      AttributeUsageAttribute類指定另一特性類的用法,有一個參數

      public AttributeUsageAttribute( AttributeTargets validOn);

      12、 怎樣確定垃圾確實被回收了,調用了supressfinalize或collect方法就一定銷毀了對象嗎?顯示調用了析構方法就一定銷毀了對象嗎?

      答:垃圾回收 GC 類提供 GC.Collect 方法,您可以使用該方法讓應用程序在一定程度上直接控制垃圾回收器,這就是強制垃圾回收。

      Finalize 方法和析構函數如何允許對象在垃圾回收器自動回收對象的內存之前執行必要的清理操作。

      對于您的應用程序創建的大多數對象,可以依靠 .NET Framework 的垃圾回收器隱式地執行所有必要的內存管理任務。但是,在您創建封裝非托管資源的對象時,當您在應用程序中使用完這些非托管資源之后,您必須顯式地釋放它們。最常見的一類非托管資源就是包裝操作系統資源的對象,例如文件、窗口或網絡連接。雖然垃圾回收器可以跟蹤封裝非托管資源的對象的生存期,但它不了解具體如何清理這些資源。對于這些類型的對象,.NET Framework 提供 Object.Finalize 方法,它允許對象在垃圾回收器回收該對象使用的內存時適當清理其非托管資源。默認情況下,Finalize 方法不執行任何操作。如果您要讓垃圾回收器在回收對象的內存之前對對象執行清理操作,您必須在類中重寫 Finalize 方法。當使用 C# 和 C++ 的托管擴展以外的編程語言進行開發時,您可以實現 Finalize 方法。C# 和托管擴展提供析構函數作為編寫終止代碼的簡化機制。析構函數自動生成 Finalize 方法和對基類的 Finalize 方法的調用。在 C# 和托管擴展編程語言中,您必須為終止代碼使用析構函數語法

      

    【新蛋科技.net工程方面的筆試題】相關文章:

    .net面試題07-25

    NET筆試題目11-06

    .NET高頻筆試題11-16

    網宿科技研發類2011筆試題07-18

    ASP.NET筆試題小匯總02-12

    NIIT .Net方向考試筆試題01-21

    綠盟科技2013全國統一筆試題12-10

    ASP.NET的一套筆試題02-12

    迅雷2011.10.21筆試題08-10

    中興2015筆試題08-02

    日韩激情