Q1. In which of these situations are interfaces better than abstract classes?
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))
Q5. What is the difference between the ref and out keywords?
Q6. How could you retrieve information about a class, as well as create an instance at runtime?
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) { }
}
}
Q8. What is the difference between an anonymous type and a regular data type?
Q9. When would you use a Dictionary rather than an Array type in your application?
Q10. What is the difference between a.Equals(b) and a == b?
Q11. Which choice best describes a deadlock situation?
Q14. Which code snippet declares an anonymous type named userData?
Q15. What will be returned when this method is executed?
public void userInput(string charParameters) { }
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);
}
Q17. Lambda expressions are often used in tandem with which of the following?
Official documentation: Language Integrated Query (LINQ) Overview
Q19. How do you make a method in an abstract class overridable?
Q20. How would you write code for an integer property called Age with a getter and setter?
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?
Q23. Which choice represents a class that inherits behavior from a base class?
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?
Q27. What is the difference between throw exceptions and throw clauses?
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?
Q31. Given this enumeration, how would you access the integer-type value of 'AppState.Loading'?
enum AppState { OffLine, Loading, Ready }
Q32. What character would you use to start a regular expression pattern at a word boundary?
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; }
}
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?
Q35. What is the most accurate description of a regular expression?
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);
}
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?
Q41. Which characteristic prevents this code from compiling?
public int age="28"
Q42. How would you serialize this class?
public class User {}
Q43. How would you write a delegate named ResultCallback with an int parameter named responseCode?
Q44. What is the difference between a static and non-static method?
Q45. What is the correct way to write an event named apiResult based on a delegate named ResultCallback?
Q46. When will the code inside finally block be executed in a try-catch statement?
Q47. What method correctly extends the string class?
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; }
}
Q52. When an object in C# is serialized, what is it converted to?
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?
Q59. How would you write an enum variable called AppState with values for Offline, Loading, and Ready?
Q60. What is the main difference between a value type and a reference type?
Q61. What is the difference between the break and continue keywords?
Q62. Which code snippet correctly declares a variable named userId with a public get and private set?
Q63. What is true about virtual methods?
Q64. What is likely to happen if you have multiple threads accessing the same resource in your program?
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
Q70. What accessibility level does this class field have?
private string LastName;
Q71. How would you correctly declare a jagged array called 'partyInvites' with 10 empty elements?
Q73. What is wrong with this code?
void MyFunction()
{
{
int a = 10;
int b = 20;
int c = a + b;
}
Console.WriteLine(c);
}
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