关于C#的问答

文中英文部分是我不明白及不肯定的地方,欢迎为我留言,引用自http://blogs.crsw.com/mark/articles/252.aspx
Q:C#支持多继承吗?
A:不
Q:protected class访问级别如何?
A:允许本类和子类访问
Q:private class变量可以被继承吗?
A:行,但不能被访问,但可以被继承
Q:描述一下protected internal
A:只有派生类型或同一程序集中的类型才能访问该成员。
Q:What does the term immutable(不可变) mean?
A:The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
我的理解:不可变值就象Strings,要通过丢弃原来的数据,再在内存中建立一个新的区来存数据 
Q:System.String 和System.Text.StringBuilder 的区别?
A:System.String is immutable.  System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed. 
Q:What’s the advantage of using System.Text.StringBuilder over System.String?
A:System.String 类是一种传统的修改字符串的方式,它确实可以完成把一个字符串添加到另一个字符串上的工作没错。但是在.NET框架下,这个操作实在是划不来。因为系统先是把两个字符串写入内存,接着删除原来的String对象,然后创建一个String对象,并读取内存中的数据赋给该对象。这一来二去的,耗了不少时间。

而使用System.Text命名空间下面的StringBuilder类就不是这样了,它提供的Append方法,能够在已有对象的原地进行字符串的修改,简单而且直接。如果想要编写将连续操作依次连接起来的单个语句,这将很方便。在有代码说明http://blog.csdn.net/zhangjianying/archive/2005/11/10/526428.aspx

Q:能将不同类型的数据存在System.Array中吗?
A:不能

Q:System.Array.CopyTo() 和 System.Array.Clone()区别?

A:The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.  The CopyTo() method copies the elements into another existing array.  Both perform a shallow copy.  A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.  A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
Clone()返回一个(新的)(拥有原始Array中所有部分的)Array对象,CopyTo()拷贝一个Array到另一个Array中
它们都是浅拷贝。
以下是在CSDN中提问的得到的解答http://community.csdn.net/Expert/topic/4578/4578956.xml?temp=.3176233
深拷贝的精确描述是这样的:对对象的所有成员进行深拷贝。
浅表拷贝则是:

对对象的所有成员进行拷贝,如果该成员是引用类型的,则只拷贝引用。

深拷贝和浅表拷贝的区别在于对象拥有引用类型成员时。
深拷贝要求对引用类型的成员也进行深拷贝。浅表拷贝则只是简单的复制引用。

假设一个对象A,它包含了B,则深拷贝会先将B进行深拷贝产生B1,再创建A1,把B1作为A1的成员。浅表拷贝因为只拷贝引用,对象B不会被复制一份。

不知道这样说你是不是能听懂。

事实上深拷贝基本是不可能完成的任务,因为它要求这个对象树上所有的对象都支持深拷贝。

Q:你怎样对ARRAY排序?
A:用Sort() 和Reverse() 方法
Q:What’s the .NET collection class that allows an element to be accessed using a unique key?
A:哈希表
Q:一个try{}可对应多个catch{}吗?
A:不行
Q:解释一下三层结构应用软件?
A:表示层Presentation (UI), 业务层Business (logic and underlying code) and Data 数据层
(from storage or other sources).  
关于类的问题
 
Q:怎样防止你的class被继承?
A:    sealed
Q:怎样使你的class可以被继承,但方法不能被重载(override)?
A:public class和sealed 方法
Q:abstract class啥意思?
A:不能被实例化的类,抽象类必须被继承,且其中的方法必须重载,本质上说是一个类(实际的类)的没有任何行为(函数中没有任何语句)的蓝图,原句:An abstract class is essentially a blueprint for a class without any implementation但abstract class中的方法可以是具体的;
Q:What happens if you inherit multiple interfaces and they have conflicting method names?
A:  It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
To Do: Investigate 
Q:接口与抽象类的区别?
A:接口中,所有方法都是抽象的(没有实现体),且没有访问级别(private,publice..)描述.
抽象类中可能有.
Q:你什么时候将一个类声明为抽象?
A:
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. 
When at least one of the methods in the class is abstract. 

Q:override和overload的区别?
A:当override了一个方法,行为是从一个派生类中发出的
overload则是在同一个类中定义的同名方法
class A{
    public vitual  void methodA(){...}
    //overload method
    public void methodA(string str){...}
}
class B:A
 {
//override method
  public override void methodA(){...} 
 }
Q:能将一个override method声明为static,但其父类的方法不是static吗?
A:不行(在override method中,除了virtual改成override,其他什么都不能改)

ADO.NET and Database Questions

Q:在ADO.net中微软的data provider 有什么缺点和优点?
A:SQLServer.NET 的data provider高速且强大,但要付钱
OLEDB.net 可以访问多种数据库数据库例如(oracle ,db2,Access Informix),但速度和效率不高。
Q:connection 对象的Dispose()方法有什么作用?
A:释放内存
 

posted @ 2006-02-26 15:05  Aldebaran's Home  阅读(1038)  评论(1编辑  收藏  举报