Some more tricky questions on .NET and C #



I have selected for you some interesting, but not very well-known questions from the world of .NET and C #. Plus, I wrote some questions myself, based on books, articles and videos that I liked.

1. What will be displayed on the screen? (if anything is displayed at all)

string nullString = (string)null;
Console.WriteLine (nullString is string);


2. What will be displayed by the console .NET application?

Console.WriteLine (Math.Round(1.5));
Console.WriteLine (Math.Round(2.5));

Answer
2 2. — . , Mono 2 3.

3. What will be the result of executing the following code:

static void Main(string[] args)
{
    float f = Sum(0.1f, 0.2f);
    float g = Sum(0.1f, 0.2f);
    Console.WriteLine(f == g);
}

static float Sum(float f1, float f2)
{
    return f1 + f2;
}

a) True
b) False
c) An exception will be thrown
d) It cannot be said unambiguously (most likely true, but it can also be false)

Answer
d
JIT float. , , CLR, ( , , ). Debug/Release , , False. , — Release False. . , .
Credits:
Binary floating point and .NET

4. What will be the result of executing the following code:

float price = 4.99F;
int quantity = 17;
float total = price * quantity;
Console.WriteLine("The total price is ${0}.", total);

a) The total price is $ 85
b) The total price is $ 84.83
c) The total price is $ 84
d) The total price is $ 84.82999


5. What is the best way to store passwords in a database? Select one or more of the answers:

a) As plaintext
b) Encrypted using DES
c) Encrypted using AES
d) Cached using MD5
e) Cached using SHA512

Answer
e
MD5 .
, keyed hash : HMACSHA1 MACTripleDES

6. In the .NET environment, there are many different timers. Which of the timers does not exist?

a) Timer from System.Windows.Forms
b) DispatchTimer from System.Windows.Threading
c) DispatchTimer from Windows.UI.XAML
d) Timer from System.Timers
e) Timer from System.Windows.Threading.Timers
f) Timer from System .Threading

Answer
e
Credits: CLR via C# Jeffrey Richter

7. What .NET REPL does not exist on the network?

a) dotnetfiddle.net
b) repl.it/languages/csharp
c) csharpcompiler.net
d) dotnet.microsoft.com/platform/try-dotnet
e) csharppad.com

Answer
c

8. If you want to indicate that the number is of type long, then you can specify the letter l or L. at the end of the number. For example, like this:

var l = 138l;

Using which letter can I specify the decimal type?

a) C or c
b) D or d
c) M or m
d) E or e

Answer
c

9. What will be displayed on the screen of the console application containing the following code:

     class Program
    {
         static Program()
        {
            Console.WriteLine("Static constructor");
        }

         public Program()
        {
            Console.WriteLine("Constructor");
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Main");
            Console.ReadLine();
        }
    }

Answer
«Static constructor» «Main»
, . . .

10. What will be displayed as a result?

      [Flags]
      public enum Status 
      {
         Funny = 0x01,
         Hilarious = 0x02,
         Boring = 0x04,
         Cool = 0x08,
         Interesting = 0x10,
         Informative = 0x20,
         Error = 0x40
      }

  public static void Main (string[] args) {
         var code = 24;
         Console.WriteLine (String.Format("This Quiz is: {0}",  (Status)code));
      }

Answer
This Quiz is: Cool Interesting

24 0011000

Funny = 0
Hilarious = 0
Boring = 0
Cool = 1
Interesting = 1
Informative = 0
Error = 0
Credits:
C# Often Surprises Me, part: 000001
Enumeration types (C# reference)


11. What is the difference between String and string?

Answer
String .NET c# string. short int C# Int16 Int32 .NET
Difference between string and String in C#

12. What does the Visual Studio symbol mean (or at least initially mean)?


13. Please map:
Async / await
Try / catch
ValidateAntiForgeryToken
with the following abbreviations:
TAP , SEH , STP

Answer
Async/await -> TAP (Task asynchronous programming model)
Try/catch -> SEH (Structured Exception Handling)
ValidateAntiForgeryToken -> STP (Synchronizer Token Pattern)

14. Which of the following is not a .NET CMS?

a) mojoPortal
b) N2 CMS
c) Atomic CMS
d) Composite C1
e) Concrete5
f) Piranha CMS

Answer
e

15. What will be displayed on the screen? (if something is displayed)

  
     class Program
    {
        private static int y = x;
        private static int x = 5;

        static void Main(string[] args)
        {
            Console.WriteLine(y);
            Console.ReadLine();
        }
    }

Answer
0


16. What class of the Concurrent Collection does not exist in .Net

a) ConcurrentQueue
b) ConcurrentStack
c) ConcurrentList
d) ConcurrentDictionary
e) ConcurrentBag

Answer
c

17. What method of calling async code in a synchronous way is preferable (of course, this is done in rare situations when await doesn’t work):

a) Wait ()
b) Result ()
c) GetAwaiter (). GetResult ()

Answer

All Articles