C # quiz

Source: Internet
Author: User
C # quiz

If you can answer the following questions correctly, you can be invincible in the face of any C # interview pen questions. Of course, this is much easier than C ++'s abnormal questions. For the correct answer, compile and run it. Good luck.

1. What is the problem with the following code?

Public Class B
{
Protected virtual void F () {console. writeline ("B ");}
}

Public Class D: B
{
Protected override void F () {console. writeline ("D ");}

Public void g (B)
{
B. F ();
}

Static void main ()
{
D = new D ();
D. G (d );
}
}

2. What are the effects of the following code?
Interface iincrementable
{
Void increment ();
}

Struct quadword: iincrementable
{
Long value;
Public void increment () {value ++ ;}
Public Static Implicit operator long (quadword q) {return Q. value ;}
}

Static class Program
{
Static void F (iincrementable Inc, int count)
{
For (INT I = 0; I <count; I ++)
Inc. increment ();
}

Static void main ()
{
Quadword q = new quadword ();
F (Q, 100 );
Console. writeline (Q );
}
}

3. What are the effects of the following code?
Class C1
{
Public static readonly int A = (INT) math. Round (math. Pi );
Public static readonly int B = c2.a;
}

Class C2
{
Public static readonly int A = c1.a;
}

Class Program
{
Static void main ()
{
Console. writeline (c1. B );
}
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.