Posted in 面试题 onJune 13, 2015
1. 填空:
1) 面向对象的语言有_______特性、_______特性、_______特性。
答:封装,继承,多态
2) ADO.NET有哪五大对象:
答:Connection,Command,DataSet,DataReader,DataAdapter
3) 能用foreach遍历访问的对象需要实现( )接口或声明( )方法的类型。
答:IEnumerable,GetEnumerable
2.多选:
1) 正确的是:BC
A.接口中可以有虚方法 B.一个类可实现多个接口
C.接口不能被实例化 D.接口中可以包含已实现的方法。
2) 读取数据库里的内容会用到以下那些:BCD
A Execute NonQuery B Execute Scalor
C fill D EXECUTE READER
3.简答:
private public internal protected 权限各自的调用方法。
答:public:不受限制的访问。
private:限定此类内部使用。
potected:除了类本身可以用外,任何继承此类的类都可以使用。
internal:表示在同一个应用程序(application)或类库(library)中都能使用。
4.写SQL语句
在SQL里取出A表中第31—40条记录。(SQLServer,以自动增长的ID做主键,注意:ID可能不是 连续的。)
答:select top 10 from a where id not in(select top 30 from a)
或 select top 10 from a where id > (select max(id) from (select top 30 from a) as b)
5、列举ASP.NET页面之间传递值的几种方式?
答:session(viewstate) 简单,但易丢失
application 全局
cookie 简单,但可能不支持,可能被伪造
input type=”hidden” 简单,可能被伪造
url参数 简单,显示于地址栏,长度有限
数据库 稳定,安全,但性能相对弱
6、 看程序写结果
Class class1
{
private string str = “class1.str”;
private int i = 0 ;
static void stringconvert (string str )
{
str = “string being converted”;
}
static void stringconvert (class1 c )
{
c. str = “string being converted”;
}
static void Add (int i)
{
i++;
}
static void AddwithRef (ref int i)
{
i++;
}
static void Main()
{
int i1 = 10;
int i2 = 20;
sting str = “str”;
classc=new class1();
Add(i1);
AddwithRef(ref i2);
Add(c.i);
stringconvert(str);
stringconvert(c);
console.WriteLine(i1);
console.WriteLine(i2);
console.WriteLine(c.i);
console.WriteLine(str);
console.WriteLine(c.str);
}
}
答:10,21,0,“str”,“string being converted”
7看程序写结果
public abstract class A
{
public A ()
{
console.writeline(‘A’);
}
public virtual void Fun()
{
console.writeline(“A.Fun()” );
}
}
public class B : A
{
public B ()
{
console.writeline(‘B’);
}
public new void Fun()
{
console.writeline(” B.Fun()” );
}
public static void Main()
{
A a = new B();
a.Fun();
}
}
答:’A’,’B’,A.fun()
8看程序写结果
public class A
{
public virtual void Fun1( int i)
{
console.writeline(i);
}
public void Fun2 ( A a )
{
a.Fun1(1);
Fun1(5);
}
}
public class B : A
{
public override void Fun1(int i)
{
base.Fun1( i+1 );
}
public static void Main()
{
B b = new B();
A a = new A();
a.Fun2(b);
b.Fun2(a);
}
}
答:2,5,1,6
9 C#设计程序: 有这样规则的几个数: 1,1,2,3,5,8,13,21,34,55…… 用递归的方法算出第30数是多少?
参考答案:
public static int add(int i)
{
if(i {
return 0;
}
else if(i == 1 || i ==2)
{
return 1;
}
else
return add(i-1)+add(i-2);
}
10 C#设计程序:
猫大叫一声。所有的老鼠都开始逃跑,主人被惊醒。
要求 1 要有联动性,老鼠和主人的行为是被动的。
2 考虑可扩展性,猫的叫声可能引起其它联动效应。
设计方法一:
public interface Observer
{
void Response(); //观察者的响应,如是老鼠见到猫的反映
}
public interface Subject
{
void AimAt(Observer obs); //针对哪些观察者,这里指猫的要扑捉的对象—老鼠
}
public class Mouse : Observer
{
private string name;
public Mouse(string name, Subject subj)
{
this.name = name;
subj.AimAt(this);
}
public void Response()
{
Console.WriteLine(name + “attempt to escape!”);
}
}
public class Master : Observer
{
public Master(Subject subj)
{
subj.AimAt(this);
}
public void Response()
{
Console.WriteLine(“Host waken!”);
}
}
public class Cat : Subject
{
private ArrayList observers;
public Cat()
{
this.observers = new ArrayList();
}
public void AimAt(Observer obs)
{
this.observers.Add(obs);
}
public void Cry()
{
Console.WriteLine(“Cat cryed!”);
foreach (Observer obs in this.observers)
{
obs.Response();
}
}
}
class MainClass
{
static void Main(string[] args)
{
Cat cat = new Cat();
Mouse mouse1 = new Mouse(mouse1, cat);
Mouse mouse2 = new Mouse(mouse2, cat);
Master master = new Master(cat);
cat.Cry();
}
}
设计方法二: 使用event — delegate设计..
public delegate void SubEventHandler();
public abstract class Subject
{
public event SubEventHandler SubEvent;
protected void FireAway()
{
if (this.SubEvent != null)
this.SubEvent();
}
}
public class Cat : Subject
{
public void Cry()
{
Console.WriteLine(“cat cryed”);
this.FireAway();
}
}
public abstract class Observer
{
public Observer(Subject sub)
{
sub.SubEvent += new SubEventHandler(Response);
}
public abstract void Response();
}
public class Mouse : Observer
{
private string name;
public Mouse(string name, Subject sub) : base(sub)
{
this.name = name;
}
public override void Response()
{
Console.WriteLine(name +“attempt to escape!”);
}
}
public class Master : Observer
{
public Master(Subject sub) : base(sub){}
public override void Response()
{
Console.WriteLine(host waken);
}
}
class Class1
{
static void Main(string[] args)
{
Cat cat = new Cat();
Mouse mouse1 = new Mouse(mouse1, cat);
Mouse mouse2 = new Mouse(mouse2, cat);
Master master = new Master(cat);
cat.Cry();
}
}
1) 面向对象的语言有_______特性、_______特性、_______特性。
答:封装,继承,多态
2) ADO.NET有哪五大对象:
答:Connection,Command,DataSet,DataReader,DataAdapter
3) 能用foreach遍历访问的对象需要实现( )接口或声明( )方法的类型。
答:IEnumerable,GetEnumerable
2.多选:
1) 正确的是:BC
A.接口中可以有虚方法 B.一个类可实现多个接口
C.接口不能被实例化 D.接口中可以包含已实现的方法。
2) 读取数据库里的内容会用到以下那些:BCD
A Execute NonQuery B Execute Scalor
C fill D EXECUTE READER
3.简答:
private public internal protected 权限各自的调用方法。
答:public:不受限制的访问。
private:限定此类内部使用。
potected:除了类本身可以用外,任何继承此类的类都可以使用。
internal:表示在同一个应用程序(application)或类库(library)中都能使用。
4.写SQL语句
在SQL里取出A表中第31—40条记录。(SQLServer,以自动增长的ID做主键,注意:ID可能不是 连续的。)
答:select top 10 from a where id not in(select top 30 from a)
或 select top 10 from a where id > (select max(id) from (select top 30 from a) as b)
5、列举ASP.NET页面之间传递值的几种方式?
答:session(viewstate) 简单,但易丢失
application 全局
cookie 简单,但可能不支持,可能被伪造
input type=”hidden” 简单,可能被伪造
url参数 简单,显示于地址栏,长度有限
数据库 稳定,安全,但性能相对弱
6、 看程序写结果
Class class1
{
private string str = “class1.str”;
private int i = 0 ;
static void stringconvert (string str )
{
str = “string being converted”;
}
static void stringconvert (class1 c )
{
c. str = “string being converted”;
}
static void Add (int i)
{
i++;
}
static void AddwithRef (ref int i)
{
i++;
}
static void Main()
{
int i1 = 10;
int i2 = 20;
sting str = “str”;
classc=new class1();
Add(i1);
AddwithRef(ref i2);
Add(c.i);
stringconvert(str);
stringconvert(c);
console.WriteLine(i1);
console.WriteLine(i2);
console.WriteLine(c.i);
console.WriteLine(str);
console.WriteLine(c.str);
}
}
答:10,21,0,“str”,“string being converted”
7看程序写结果
public abstract class A
{
public A ()
{
console.writeline(‘A’);
}
public virtual void Fun()
{
console.writeline(“A.Fun()” );
}
}
public class B : A
{
public B ()
{
console.writeline(‘B’);
}
public new void Fun()
{
console.writeline(” B.Fun()” );
}
public static void Main()
{
A a = new B();
a.Fun();
}
}
答:’A’,’B’,A.fun()
8看程序写结果
public class A
{
public virtual void Fun1( int i)
{
console.writeline(i);
}
public void Fun2 ( A a )
{
a.Fun1(1);
Fun1(5);
}
}
public class B : A
{
public override void Fun1(int i)
{
base.Fun1( i+1 );
}
public static void Main()
{
B b = new B();
A a = new A();
a.Fun2(b);
b.Fun2(a);
}
}
答:2,5,1,6
9 C#设计程序: 有这样规则的几个数: 1,1,2,3,5,8,13,21,34,55…… 用递归的方法算出第30数是多少?
参考答案:
public static int add(int i)
{
if(i {
return 0;
}
else if(i == 1 || i ==2)
{
return 1;
}
else
return add(i-1)+add(i-2);
}
10 C#设计程序:
猫大叫一声。所有的老鼠都开始逃跑,主人被惊醒。
要求 1 要有联动性,老鼠和主人的行为是被动的。
2 考虑可扩展性,猫的叫声可能引起其它联动效应。
设计方法一:
public interface Observer
{
void Response(); //观察者的响应,如是老鼠见到猫的反映
}
public interface Subject
{
void AimAt(Observer obs); //针对哪些观察者,这里指猫的要扑捉的对象—老鼠
}
public class Mouse : Observer
{
private string name;
public Mouse(string name, Subject subj)
{
this.name = name;
subj.AimAt(this);
}
public void Response()
{
Console.WriteLine(name + “attempt to escape!”);
}
}
public class Master : Observer
{
public Master(Subject subj)
{
subj.AimAt(this);
}
public void Response()
{
Console.WriteLine(“Host waken!”);
}
}
public class Cat : Subject
{
private ArrayList observers;
public Cat()
{
this.observers = new ArrayList();
}
public void AimAt(Observer obs)
{
this.observers.Add(obs);
}
public void Cry()
{
Console.WriteLine(“Cat cryed!”);
foreach (Observer obs in this.observers)
{
obs.Response();
}
}
}
class MainClass
{
static void Main(string[] args)
{
Cat cat = new Cat();
Mouse mouse1 = new Mouse(mouse1, cat);
Mouse mouse2 = new Mouse(mouse2, cat);
Master master = new Master(cat);
cat.Cry();
}
}
设计方法二: 使用event — delegate设计..
public delegate void SubEventHandler();
public abstract class Subject
{
public event SubEventHandler SubEvent;
protected void FireAway()
{
if (this.SubEvent != null)
this.SubEvent();
}
}
public class Cat : Subject
{
public void Cry()
{
Console.WriteLine(“cat cryed”);
this.FireAway();
}
}
public abstract class Observer
{
public Observer(Subject sub)
{
sub.SubEvent += new SubEventHandler(Response);
}
public abstract void Response();
}
public class Mouse : Observer
{
private string name;
public Mouse(string name, Subject sub) : base(sub)
{
this.name = name;
}
public override void Response()
{
Console.WriteLine(name +“attempt to escape!”);
}
}
public class Master : Observer
{
public Master(Subject sub) : base(sub){}
public override void Response()
{
Console.WriteLine(host waken);
}
}
class Class1
{
static void Main(string[] args)
{
Cat cat = new Cat();
Mouse mouse1 = new Mouse(mouse1, cat);
Mouse mouse2 = new Mouse(mouse2, cat);
Master master = new Master(cat);
cat.Cry();
}
}
武汉世纪畅想数字传播有限公司 .NET笔试题
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@