zoukankan      html  css  js  c++  java
  • 北航软院2013级C#期末考试部分考题解答

    博主注:本渣渣水平有限,文中若有不对的地方敬请指出,谢谢。

    本文中大部分图片来自老师的PPT,感谢邵老师,想要的可以点击右边QQ联系我:)

    一、选择题

    2.Wrong statement?

    A.double a = 2E15;   B. long b = 0x10Cl;   C. string c = @””””;   D.int d = 2014;

    解答:本来一眼看过去是没什么问题的(事实也确实没有问题),如果说我把C选项复制到VS里显示的是中文引号也算错误的话,也只能是这个错误了(开玩笑的。大雾)

    这道题唯一的看点,那就是C选项中的字符串c是什么呢?答案是一个<">。@可以不管转义,符特殊情况,两个<">代表一个<">。

    C#中@的作用:

    1.用@可以不用写转义字符。如文件路径,可以不用写两个反斜杠,即忽略转义

    2.可以让字符串跨行。

    3.c#中是不允许用关键字作为标识符的,但是在关键字前加上@,就打破了这个界限。@int是可以存在,当做变量的。


    3.有这样一个类List,class List : IList, 以下正确的是:

    1)IList a=new IList()    2) List b= new List()

    A 1)   B 1)2)  C 2)  D neither 1) nor 2)

    解答:这里的IList我们默认是接口(接口的命名是这样的),接口是不能实例化的,所以1)是错的,2)当然对啦~~~

    还有一种操作,那就是IList ex=new List();

    邵老师告诉我们:

     


    4.right answer

    A Structs cannot have a parameterless constructor.

    B Structs can have a destructor.

    C

    解答:A看起来怪怪的,不论什么时候,编译器都会给结构体一个默认无参构造器,也会拒绝你给它的无参构造器,所以这里说结构体无参构造器没有不太好,意思懂了就行。类就不一样了,你不给它它就自己造一个无参构造器,你给它一个构造器(不论有参无参),它就不管了,不给你默认无参构造器了。


    5. right answer

    One file could have multiple namespaces.(说法正确)

    File name ,directory,的关系

    解答:这里讲一下有关于namespace方面的小知识点吧。

    1. 程序如果不指定namespace,它是有默认的namespace的。
    2. namespace可以嵌套名字空间、结构体、接口、代理、类、枚举
    3. namespace是可以在多个文件中定义的,编译时会合为一体。
    4. namespace允许别名操作:using F = System.Windows.Forms;F.Button b;
    5. 在一个namespace里面可以using其他名字空间


    6. In C#, which of the types is value types?

    A Enums B delegates C interfaces D class

    解答:最后一次复习值类型:Primitive Types(bool、int等)、Enums、Structs。


     7.Which of the statements is correct to declare a two-dimensional array in C#?

    A int[,] myArray B int myArray[][]

    C int[2] myArray DSystem.Array[2] myArray

    解答:

    //一维
                int[] a = new int[3];
                int[] b = new int[] { 3, 4, 5 };
                int[] c = { 3, 4, 5 };
    
                //非矩阵二维数组
                //int wrong1[1][2];//错误
                
                int[][] aa = new int[2][];// array of references to other arrays
                aa[0] = new int[] { 1, 2, 3 };// cannot be initialized directly
                aa[1] = new int[] { 4, 5, 6 };
    
                //矩阵二维数组
                int[,] aaa = new int[2, 3];// block matrix
                int[,] bbb = { { 1, 2, 3 }, { 4, 5, 6 } };// can be initialized directly
                int[,,] ccc = new int[2, 4, 2];
    View Code

    10. The statement f = delegate(int x){return x + 1;}; is equivalent to which of the following statements?

    A.f(x) =>x + 1;

    B.f(x) = x + 1;

    C.f => x + 1;

    D.f = x => x + 1;(见上一篇博客原题)


    11. 11级的12题 关于线程 Resume

    12. 11级的13题 泛型

    13. In C#,__is a set of types that are compiled together and it is the smallest unit for deployment and dynamic loading.

    A assembly B class C namespace D package

    解答:个人认为程序集是一个挺难懂的问题,至今没弄会。只知道.exe和.dll是程序集。


     14.把declarationPPT的最后一页弄明白就会了(PPT75~83,重点看77以及其他每页的最后一句话。)

    15. right answer

    A overflow can be detected by default.

    B sizeof can be applied to reference types

    解答:A是错的,两个大int相加他是不会出现什么意外的。B是错的,sizeof只能用于值类型。


    二、判断题

    1. Constants can be declared static

    解答:F),系统报错,在C#中const与static不能同时修饰变量;

    你问我为什么?邵老师表示C#有的事情就是这么没有理由:)


    2. All types are compatible with object.

    解答:T),


    3.Enumerations cannot be assigned to int. 

    解答:T


    4.In C#, converting a value type to a reference type is called unboxing and converting a reference type to a value type is called boxing.

    解答:F)反了gg


     5 nested types can be interfaces and delegates

    解答:T


     7 operand types can only be numeric or char

    解答:F


     8 Identifier can be Chinese characters

    解答:(T),只要是Unicode就可以了~C#很棒吧!


    三、填空

    4. An interface member is _implemented __or _inherited__from a base class

    解答:接口的成员要么自己定义要么继承自父类。

    接口不能包含常量、字段、操作符、构造函数、析构函数、任何静态成员、方法的实现


    5 The visibility of an interface member is __public____.


     6.In C#, all exception classes are derived from _System.Exception___class.


    7. 题目见代码,应该是问输出什么。

    using System;
    class A
    {
        public int x;
        public void F()
        {
            Console.WriteLine("AFx"+x);
        }
        public virtual void G()
        {
            Console.WriteLine("AGx"+x);
        }
    }
    class B : A
    {
        public new int x;
        public new void F()
        {
            Console.WriteLine("BFx"+x);
        }
        public new void G()
        {
            Console.WriteLine("BGx"+x);
        }
    }
    
    class Test
    {
        public static void Main()
        {
            B b = new B();
            b.x = 1;      // accesses B.x
            b.F();
            b.G();
            ((A)b).x = 2;
            ((A)b).F();
            ((A)b).G();
    
            Console.ReadKey();
        }
    }
    View Code

    解答:考查的是new的用法,new就是重新开始,打断继承。

    运行结果:


    四、解答题

    1.why are properties often a good idea? Explain the reason why we use properties(属性)

    解答:使用属性的好处:允许只读或者只写字段;可以在访问时验证字段;接口和实现的数据可以不同;替换接口中的数据。


    2.What is the difference between value type and reference type?

    解答:值类型直接存储其值,而引用类型存储对其值的引用。

    值类型部署在栈上,引用类型部署在托管堆上。

    具体详解:http://blog.csdn.net/qiaoquan3/article/details/51202926

     


    3.What is the difference between private assembly and public assembly?

    解答:咱用中文回答应该没问题:)

    private assembly只能被一个应用程序使用、保存在应用程序目录中、不要求强命名、无法签名;

    public assembly可以被所用应用程序使用、保存在全局程序集中、必须有一个强命名、可以签名

    另外强命名包括四个部分:Assembly的命名、Assembly的版本号、Assembly的文化属性、Assembly的公钥。


    4.What is the difference between class and struct?

    解答:个人又总结了一遍。

    1.结构体实值类型的,而类是引用类型的。

    2.结构体的实例部署在栈上,而类的实例部署在堆上。

    3.结构体和类都有构造器,但是不能为结构体声明无参数的构造器,而类可以。

    4.如果声明有参数构造器,对于结构体来说编译器仍然会生成默认无参构造器,而类不会。

    5.如果构造器中不初始化字段,对于结构体,编译器不会自动初始化,而类会。

    6.结构体声明字段时不可以初始化,而类可以。

    7.结构体不可以从另一个结构体或类继承而来,也不可以被继承;而类可以从另一个类继承而来,也可以被继承(除非为sealed类)。

    8.结构体和类都可以继承多个接口。

    9.结构体没有析构函数,而类可以有(一般不用)。

    最后,大家加油呀,祝明天考试顺利~

    作者: AlvinZH

    出处: http://www.cnblogs.com/AlvinZH/

    本文版权归作者AlvinZH和博客园所有,欢迎转载和商用,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    String方法
    多态
    观察者模式
    ArrayList和LinkList
    唐岛湾
    AForge.Net C#的操作视频,照片读写功能
    JqGrid填坑
    日常点滴
    日常点滴
    EF Core 填坑记录
  • 原文地址:https://www.cnblogs.com/AlvinZH/p/6838795.html
Copyright © 2011-2022 走看看