linkedin-skill-assessments-quizzes

C#

Q1. In which of these situations are interfaces better than abstract classes?

Q2. Which statement is true of delegates?

Official documentation: Delegates

Q3. Which choice best defines C#’s asynchronous programming model?

Official documentation: Task asynchronous programming model resposta correta --> var contacts = new List();

Q4. How would you determine if a class has a particular attribute?

var type = typeof(SomeType);
var attribute = type.GetCustomAttribute<SomeAttribute>();
var typeof(MyPresentationModel).Should().BeDecoratedWith<SomeAttribute>();
Attribute.GetCustomAttribute, typeof(SubControllerActionToViewDataAttribute)
Attribute.GetCustomAttribute(typeof(ExampleController), typeof(SubControllerActionToViewDataAttribute))
  1. Official documentation: Attribute Class
  2. Official documentation: Attribute.GetCustomAttribute Method

Q5. What is the difference between the ref and out keywords?

  1. Official documentation: ref
  2. Official documentation: out parameter modifier

Q6. How could you retrieve information about a class, as well as create an instance at runtime?

Official documentation: Reflection

Q7. What is this code an example of?

    private static object objA;
    private static object objB;

    private static void performTaskA()
    {
        lock (objB)
        {
            Thread.Sleep(1000);
            lock (objA) { }
        }
    }

    private static void PerformTaskB()
    {
        lock (objA)
        {
            lock (objB) { }
        }
    }

Official documentation: Deadlocks and race conditions

Q8. What is the difference between an anonymous type and a regular data type?

Official documentation: Anonymous Types

Q9. When would you use a Dictionary rather than an Array type in your application?

Official documentation: Dictionary<TKey,TValue> Class

Q10. What is the difference between a.Equals(b) and a == b?

  1. Official documentation: Object.Equals
  2. c-sharpcorner: Equality Operator(==) vs .Equals()

Q11. Which choice best describes a deadlock situation?

Official documentation: Deadlocks and race conditions

Q12. How does the async keyword work?

Official documentation: async

Q13. What is an object in C#?

Official documentation: Objects

Q14. Which code snippet declares an anonymous type named userData?

Official documentation: Anonymous Types

Q15. What will be returned when this method is executed?

public void userInput(string charParameters) { }

Official documentation: void

Q16. In what order would the employee names in this example be printed to the console?

string[] employees = { "Joe", "Bob", "Carol", "Alice", "Will" };

IEnumerable<string> employeeQuery = from person in employees
                                    orderby person
                                    select person;

foreach(string employee in employeeQuery)
{
    Console.WriteLine(employee);
}

dotnetpattern: LINQ OrderBy Operator

Q17. Lambda expressions are often used in tandem with which of the following?

Official documentation: Language Integrated Query (LINQ) Overview

Q18. What is the correct formatting for single-line and multiline comments?

w3schools: C# Comments

Q19. How do you make a method in an abstract class overridable?

  1. Official documentation: virtual
  2. Official documentation: abstract

Q20. How would you write code for an integer property called Age with a getter and setter?

Official documentation: Using Properties

Q21. What is an abstract class?

Official documentation: Abstract and Sealed Classes and Class Members

Q22. When using a thread pool what happens to a given thread after it finishes its task?

Official documentation: Thread pool characteristics

Q23. Which choice represents a class that inherits behavior from a base class?

Official documentation: Inheritance

Q24. What does operator overloading allow you to do?

Official documentation: Operator overloading

Q25. What is the main purpose of LINQ?

Official documentation: Language Integrated Query (LINQ) Overview

Q26. What is the correct syntax for a new generic list of strings named contacts?

[Official documentation: List Class](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=net-5.0)

Q27. What is the difference between throw exceptions and throw clauses?

  1. Official documentation: throw
  2. c-sharpcorner: Difference Between Throw Exception and Throw Clause

Q28. When an asynchronous method is executed, the code runs but nothing happens other than a compiler warning. What is most likely causing the method to not return anything?

Official documentation: Starting tasks concurrently

Q29. What are C# events?

Official documentation: Introduction to events

Q30. What kind of values can arrays store?

Official documentation: Arrays

Q31. Given this enumeration, how would you access the integer-type value of ‘AppState.Loading’?

enum AppState { OffLine, Loading, Ready }

Official documentation: Enumeration types

Q32. What character would you use to start a regular expression pattern at a word boundary?

  1. regular-expressions: Word Boundaries
  2. Official documentation: Regular Expression Language - Quick Reference

Q33. To conform to the following interface, which of its members need to be implemented?

public interface INameable
{
    string FirstName { get; set; }
    string LastName { get; }
}

Official documentation: interface

Q34. You’re dealing with multiple assemblies in your program, but are worried about memory allocation. At what point in the program life cycle are assemblies loaded into memory?

  1. Official documentation: Assembly Loading
  2. Stackoverflow: When exactly are assemblies loaded?

Q35. What is the most accurate description of a regular expression?

  1. Official documentation: Regular Expression Language - Quick Reference
  2. Official documentation: .NET regular expressions

Q36. Why would you use a class field in C#

Official documentation: Introduction to classes

Q37. When would you use generics in your code?

Official documentation: Generic classes and methods

Q38. What prints to the console when this code is executed?

public delegate void AuthCallback(bool validUser);
public static AuthCallback loginCallback = Login;
public static void Login()
{
    Console.WriteLine("Valid user!");
}

public static void Main(string[] args)
{
    loginCallback(true);
}
  1. Official documentation: Introduction to Delegates
  2. Official documentation: Introduction to Events

Q39. How would you declare a sealed class named User?

Official documentation: Abstract and Sealed Classes and Class Members

Q40. What is the difference between non-static and static classes?

  1. stackoverflow
  2. Official documentation: Static Constructors

Q41. Which characteristic prevents this code from compiling?

public int age="28"

c-sharpcorner: Type Safety in .NET

Q42. How would you serialize this class?

public class User {}

Official documentation: SerializableAttribute Class

Q43. How would you write a delegate named ResultCallback with an int parameter named responseCode?

Official documentation: Delegates

Q44. What is the difference between a static and non-static method?

Official documentation: Static Members

Q45. What is the correct way to write an event named apiResult based on a delegate named ResultCallback?

Official documentation: Introduction to events

Q46. When will the code inside finally block be executed in a try-catch statement?

Official documentation: try-catch

Q47. What method correctly extends the string class?

Q48. How are C# classes limited?

Official documentation: Class inheritance

Q49. What function do namespaces perform?

Official documentation: namespace

Q50. What is the correct way to write a public property with a private backing field?

private int _password;
pubic int Password = { get; set; }
private int _password;
public int Password = _password;
private int _password;
public int Password
{
  get -> _password;
  set-> _password = value;
}
private int _password;
public int Password
{
  get { return _password; }
  set { _password = value; }
}

Official documentation: Using Properties

Q51. What is a thread pool?

Official documentation: ThreadPool Class

Q52. When an object in C# is serialized, what is it converted to?

Official documentation: Serialization

Q53. What is a delegate

Official documentation: Delegates

Q54. What are the four keywords associated with exception handling in C#?

Tutorial Point

Q55. What is the main difference between the is and as operators?

Pluralsight guide

Q56. What is the difference between finally and finalize blocks?

C-sharpcorner

Q57. Your application has a value type called username that needs to be able to accept null values, but this is generating compile-time errors. How would you fix this in code?

Q58. Which code snippet correctly declares a custom exception named InvalidResponse?

Official documentation: Exceptions

Q59. How would you write an enum variable called AppState with values for Offline, Loading, and Ready?

Official documentation: Enum

Q60. What is the main difference between a value type and a reference type?

  1. Official documentation: Value types
  2. Official documentation: Reference types

Q61. What is the difference between the break and continue keywords?

Official documentation: Jump statements

Q62. Which code snippet correctly declares a variable named userId with a public get and private set?

Official documentation: Properties

Q63. What is true about virtual methods?

  1. Official documentation: virtual
  2. c-sharpcorner: Virtual Method in C#

Q64. What is likely to happen if you have multiple threads accessing the same resource in your program?

Official documentation: race conditions

Q65. How do you indicate that a string might be null?

Official documentation: nullable value types

Q66. Do you need to declare an out variable before you use it?

Q67. How would you access the last two people in an array named People?

Explain: You can do this in C#. However, none of the above answers are correct. You can access the last two items by using People[^2..]. Please see issue #3354 for more information. See also: Official Documentation: Ranges

Q68. When can anonymous types be created?

C-sharpcorner: Anonymous Types

Q69. What is true about thread multitasking?

Official Documentation: Threads

Q70. What accessibility level does this class field have?

private string LastName;

Official Documentation: Accessibility Levels

Q71. How would you correctly declare a jagged array called ‘partyInvites’ with 10 empty elements?

Official Documentation: Jagged Arrays

Q72. How could you pause a thread for three seconds?

Reference

Q73. What is wrong with this code?

void MyFunction()
{
    {
        int a = 10;
        int b = 20;
        int c = a + b;
    }

    Console.WriteLine(c);
}

Reference

Q74. Which statement is True?

Reference

Q75. How would you return more than one value from a method?

Q76. Which is a valid example of a derived class?

Q77. What is the correct way to call a static method named DebugString from a static class called InputManager?

Q78. What values can be assigned to this variable?

public string? nickname

Q79. What is a destructor?

Reference

Q80. Which code snippet correctly declares a CustomInt type alias of type Int32?

Reference

Q81. What is an enumeration type?

Q82. What is the readonly keyword used for in-field declarations?

Q83. Which statement is true of C# methods?

Official documentation: Methods (C# Programming Guide)

Q84 Which is a valid built-in C# Exception class?

Official documentation: ArgumentNullException Class

Q85. What is the purpose of an interface in C#?

Official Documentation: Interfaces (C# Programming Guide)

Q86. What is the primary purpose of the finally block in a C# try-catch-finally statement?

Official Documentation: try-catch (C# Reference)

Q87. Which data structure in C# allows you to store key-value pairs and is often used for quick data retrieval?

Official Documentation: Dictionary<TKey, TValue> Class

Q88 The execution of the program begins with?

Q89 In C# ‘using’ is a?