面试前先了解笔试吧。以下是CN人才网小编为大家精心搜集和整理的新蛋科技.net工程方面的笔试题,希望大家喜欢!
新蛋科技.net工程方面的笔试题
1、 DataSet和DataReader的区别和相同点,分别适合用于什么样的情况?
答:
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 方法和析构函数如何允许对象在垃圾回收器自动回收对象的内存之前执行必要的清理操作。