问题集锦

1. try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会 不会被执行,什么时候被执行,在return前还是后?
  • 答:会执行,在return前执行。

     

    2. short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错 ?

  • 答:short s1 = 1; s1 = s1 + 1;有错,s1是short型,s1+1是int型,不能显式
  • 转化为short型。可修改为s1 =(short)(s1 + 1) 。short s1 = 1; s1 += 1正
  • 确。

    long型没关系

  •  

     3. 获取分数最低的记录(可能有多条) SELECT TOP 1  with ties *
      FROM [test].[dbo].[users] order by score asc

    注:使用with ties 必须 有order by

  • 4. 虚函数

     

    static void Main(string[] args)
            {       A a = new A(); C c = new C();  }

     

       public class A
        {public A(){ Console.WriteLine("DEBUG: A constructing"); this.GetYear();}

          public virtual void GetYear(){Console.WriteLine("A");}
        }

        public class B:A
        {public B():base(){Console.WriteLine("DEBUG: B constructing");this.GetYear();}

          public override void GetYear(){Console.WriteLine("B");}
        }

        public class C : B
        {public C(){Console.WriteLine("DEBUG : C constructing");this.GetYear();}

           public override void GetYear(){Console.WriteLine("C");}

    }

     

    DEBUG: A constructing

    A

    DEBUG: A constructing

    C

    DEBUG: B constructing

    C

    DEBUG: C constructing

    C

     

    你可能感兴趣的:(问题)