Csharp - Collated - Updated
Csharp - Collated - Updated
f = 0;
while (f < 3) {
Console.WriteLine(f);
f++;
}
0
1
2
0
General Information
1
2
0
1
2
1
2
3
1
2
3
0
1
2
0
1
2
3
0
1
2
3
I don't know yet.
3. The following code defines a public delegate and the method it will call:
public delegate void delegateName(string message);
public static void delegateMethod(string message)
{
Console.WriteLine(message);
}
How would you call this delegate?
Add a using statement for the delegate to the class level where your method exists and call the
delegate from a class level static method.
Create a new instance of the delegate and call the delegate from a class level static method.
Directly call the delegate.
Instantiate the delegate and call the instance.
I don't know yet.
General Information
What is the difference between these two variables?
surnames1 is a single dimension array, whereas surnames2 is a multidimensional array.
surnames1 and surnames2 are the same functionally, but use different syntax.
surnames1 is a jagged array and surnames2 is a multidimensional array.
surnames1 is a reference to a multidimensional array and surnames2 is a reference to a jagged
array.
I don't know yet.
General Information
7. What is true about records?
They are mutable by default
They are immutable in positional syntax
They cannot be inherited
They cannot be declared abstract
I don't know yet.
9. You write a suitable type called Language with appropriate constructors and a Name property.
What is the output of the following code depending on its type?
Language x = new Language(Name: "C#");
Language y = x;
x.Name = "VB";
Console.WriteLine(y.Name);
"VB" if Language is a struct
"C#" if Language is a class
"C#" in all cases
"C#" if Language is a struct
"VB" if Language is a class
"VB" in all cases
I don't know yet.
General Information
IEnumerable<int> newAges = ages.Distinct();
I don't know yet.
11. Which primitive type would be able to hold the number 55,000?
short
ushort
byte
sbyte
I don't know yet.
12. The following declaration of a variable stores the current estimated value of distance between
two given objects:
public double estimatedDistance;
You create the following method to do some calculations and return a reference to this variable, but this
code results in a syntax error. How can you fix this?
public ref double GetEstimatedDistance() {
//do some calculations
return estimatedDistance;
}
Add the ref keyword to the return statement in GetEstimatedDistance() and remove it from the
method declaration:
public double GetEstimatedDistance() {
return ref estimatedDistance;
}
Change the return type of the method to void.
Declare the estimatedDistance variable with the ref keyword:
public ref double estimatedDistance;
Add the ref keyword to the return statement in GetEstimatedDistance():
return ref estimatedDistance;
I don't know yet.
class InnerClass {
InnerClass() { }
//other stuff
General Information
}
}
You try to increment the myInt variable in the InnerClass constructor but cannot. What can you change
to access that variable?
Declare both InnerClass and OuterClass as public.
Declare OuterClass as public.
Pass OuterClass as an argument in the InnerClass constructor.
Declare a second myInt variable in InnerClass and increment that one.
I don't know yet.
15. The current date is November 25, 2025 and the current time is 1:00 PM. What will the
output to the console be once the following function executes?
private void PrintOutDateTime()
{
DateTime localDate = DateTime.Now;
var n = localDate.Month + 5;
var culture = new System.Globalization.CultureInfo("en-US");
//Line 1
Console.WriteLine(localDate.ToString(culture));
//Line 2
Console.WriteLine(localDate.ToString("M/d/yyyy"));
//Line 3
Console.WriteLine(n);
}
11/25/2025 1:00:00 PM
11/25/2025
16
11/25/25 1:00 PM
11/25/2025
April
General Information
16.What is wrong with the following code?
public abstract record Person {
public string FirstName { get; init; }
public string LastName { get; init; }
public Person(string firstName, string lastName)
=> (FirstName, LastName) = (firstName, lastName);
public void Deconstruct(out string firstName, out string lastName)
=> (firstName, lastName) = (FirstName, LastName);
}
Either both Person and Student must be declared as abstract or neither should be
A base record and a sub record cannot both have a Deconstruct method
A constructor is always required in a record class
17. There are multiple tasks from a single thread and you must propagate any exceptions
back to the calling thread, handling each exception individually. How can you do so?
By catching System.AggregateException and iterating over its InnerExceptions collection
By starting each task with the optional parameter of .wait() and logging exceptions before
continuing with the next task
By catching Aggregate.TaskException and iterating over its InnerExceptions collection
By wrapping the multiple tasks within a try/catch block, logging any errors, and
running continue() on the next task
I don't know yet.
General Information
Imports the System.dll assembly and allows types in that assembly to be referenced without
specifying the namespace
Allows types in the System namespace to be referenced without specifying the namespace
explicitly
Imports the System.dll assembly, so that types in that assembly can be used
Places the System library file in temporary memory
I don't know yet.
Which code block correctly references this class and its static members with no syntax errors?
public class Bird
{
public static int NumberOfLegs = 2;
public static bool CanFly = true;
Bird.BirdDescription();
int numLegs = Bird.NumberOfLegs;
bool canFly = Bird.CanFly;
General Information
The following try/catch block results in the loss of the current stack trace, and a new stack trace is
started at the current method:
try {
//try statements
} catch (Exception e) {
throw e;
}
What change can you make to preserve the entire stack trace?
Remove the e in the catch declaration:
catch (Exception) {
throw e;
}
Remove the e in the throw statement:
catch (Exception e) {
throw;
}
Add a finally statement to the end.
Add a finally statement between the try and catch statements.
I don't know yet.
If the conversion fails, then the first snippet sets value1 to null, but the second
snippet throws an exception.
The first snippet only compiles if an explicit cast exists from the type of source to
MyClass, the second snippet requires an implicit cast to exist.
If the conversion fails, then the first snippet throws an exception, but the
second snippet sets value2 to null.
value1 is statically typed as MyClass, but value2 is dynamically typed at runtime
to the actual type of source refers to.
I don't know yet.
~ErrorLog()
{
CleanupResources();
General Information
}
When will this member be invoked?
As soon as theErrorLog instance goes out of scope.
At some undetermined time but not until after ALL ErrorLog instances that exist
in the app have fallen out of scope.
Your choice: incorrect -During final cleanup just before the app or process being
executed closes.
At some undetermined time after the ErrorLog instance has been marked for
garbage collection.
I don't know yet.
4. Which data type would normally be recommended to store monetary values intended to
be used in currency calculations?
decimal
float
ulong
double
don't know yet.
General Information
Private members are visible only in a derived class if the derived class is nested
inside their base class.
Static members are visible only in a derived class if the derived classes are nested
in their base class.
Finalizer members are visible only in a derived class if the derived classes are
nested in their base class.
Const members are visible only in a derived class if the derived classes are nested
in their base class.
I don't know yet.
7. You have a function that makes use of the await operator because evaluation may have to
be suspended at some point to allow the operation to complete. How would you declare
this function for it to be valid?
General Information
9. Which LINQ method returns a Boolean value?
Any()
Count()
NotNull()
FirstOrDefault()
I don't know yet.
11. Given the following dictionary, which statement would you use to find the value of the
element with the key value of "NV"?
General Information
IDictionary<string, string> states =
new Dictionary<string, string>();
12. Which loop statement will produce a value of 25 in the Console.WriteLine() statement at
the bottom?
int x = 1;
while (x <= 25)
General Information
{
x++;
}
Console.WriteLine("x: " + x);
int x = 1;
while (x <= 25)
{
x++;
}
Console.WriteLine("x: " + x);
int x = 1;
do
{
x++;
} while (x < 25);
Console.WriteLine("x: " + x);
int x;
while (x == 0 || x < 26)
{
x++;
}
Console.WriteLine("x: " + x);
I don't know yet.
13. How do you declare a generic method called Test that takes one parameter which must be
a value type?
public void Test<T : struct>(T t)
{ /* ... */ }
public void Test<T>(T t) where : T is struct
{ /* ... */ }
public void Test<struct T>(T t)
{ /* ... */ }
public void Test<T>(T t) where T : struct
{ /* ... */ }
I don't know yet.
14. Given these two method overloads:
public static class NumberWriter
{
public static void Display(int x)
{
Console.WriteLine("Integer: " + x);
}
public static void Display(long x)
{
General Information
Console.WriteLine("Long: " + x);
}
}
What will the following code do?
short value = 10;
NumberWriter.Display(value);
It will throw a RuntimeBinderException because the call to Display is ambiguous.
It won't compile because the call to Display is ambiguous.
It will display Long: 10.
It will display Integer: 10.
I don't know yet.
15. Which statement accurately describes the Language Integrated Query (LINQ) extension method
Union()?
Union() returns all the values from two collections.
Union() returns all values from a collection and distinct values from a second collection.
Union() returns all values from one collection not found in a second collection.
Union() returns values from two collections, excluding duplicates.
I don't know yet.
16. Consider the following code: Order newOrder = new Order() {PartId="Ms23-49"}; What must the
Order class contain for this code to compile?
An attribute that takes a string parameter called PartId
A constructor that takes a string parameter called PartId and an attribute that allows a
string property called PartId to be set
A constructor that takes a string parameter called PartId
A default constructor (either explicit or compiler-generated) and a writeable string
property called PartId
I don't know yet.
17. Consider the following array, Language Integrated Query (LINQ) query, and result:
// Array
List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };
// LINQ Query
var distinctAges = ages.Distinct();
// query result
distinctAges = {21, 46, 55, 17};
What change must you make to the LINQ query to return the average of the distinct values?
General Information
Replace Distinct() with AverageDistinct()
Change Distinct() to Select(x => x.Distinct).Average()
Add the Average() extension method after Distinct()
Change Distinct() to Average(x => x.Distinct)
I don't know yet.
SelectMany() uses on-demand, real-time execution to return values as objects from the
petOwners array.
SelectMany() projects the first and last element of a sequence.
SelectMany() enables the LINQ query to return the result set without the need for
enumeration such as foreach in C#.
SelectMany() returns a flattened projection of the array petOwners.
I don't know yet.
19. What is the visibility of the currentSpeed variable in the following code? public class Automobile
{
double currentSpeed {get; set;}
}
General Information
public
protected
private
internal
I don't know yet.
20. The following code results in a compilation error. What must you change to correct this error?
public class TestAction1
{
public static void Main()
{
Action<T> messageTarget;
if (Environment.GetCommandLineArgs().Length >
messageTarget = ShowWindowsMessage;
else
messageTarget = Console.WriteLine;
messageTarget("Hello, World!");
}
private static void ShowWindowsMessage(string message)
{
MessageBox.Show(message);
}
}
General Information
public class MyClass {
public static void Main(string[] args) {
Interface1 inti = new Interface1();
//more implementation
}
}
General Information
24. A unit test must have full control of the system it is testing. This can be problematic when the
production code includes calls to static references such as DateTime.Now. Which approach
resolves these challenges?
Create unique stubs for all class methods requiring tests.
Write mock methods controlled with a library and have the production code depend on
that interface.
Extend all methods that you must control with an interface.
Define an interface that can be mocked and have the production code depend on that
interface.
I don't know yet.
25. What type of key is being used in this Language Integrated Query (LINQ) to join the data from
three tables?
var query = from o in db.Orders
from p in db.Products
join d in db.OrderDetails
on new {o.OrderID, p.ProductID} equals new {d.OrderID, d.ProductID} into details
from d in details
select new {o.OrderID, p.ProductID, d.UnitPrice};
Multi key
Primary key
Unique key
Composite key
I don't know yet.
27. If arr is an array of int, how can you obtain the number of elements in arr?
arr.Length
arr.Length()
arr.Count
arr.Size()
I don't know yet.
General Information
28. You wrote a class MyClass that overrides a base class method virtual void DoSomething(). How
can you prevent the MyClass override of DoSomething from being further overridden?
Declare the method as private override in MyClass.
Declare the method as public override in MyClass.
Declare the method DoSomething as sealed override.
Declare the method as public virtual sealed in MyClass.
I don't know yet.
29. Which Threading.Task method will create a task that will complete when any of the associated
tasks have completed?
Task.GetAwaiter()
Task.FromResult()
Task.WhenAny()
Task.WhenAll()
I don't know yet.
General Information
An event allows a single subscriber, but the subscriber can handle multiple events from
multiple publishers.
The publisher determines when an event is raised; the subscribers determine what
action is taken in response to the event.
When an event has multiple subscribers, the event handlers are always invoked
asynchronously when an event is raised.
I don't know yet.
33. The following try/catch block results in the loss of the current stack trace, and a new stack trace
is started at the current method:
try {
//try statements
} catch (Exception e) {
throw e;
}
What change can you make to preserve the entire stack trace?
Add a finally statement between the try and catch statements.
Remove the e in the throw statement:
catch (Exception e) {
throw;
}
Remove the e in the catch declaration:
catch (Exception) {
throw e;
}
Add a finally statement to the end.
I don't know yet.
General Information
1
1
2
3
3
1
2
2
3
1
1
2
3
2
1
35. The following lines of code are declarations of the same multidimensional array (arr):
// Declaration 1
int[,] arr = new int[,] { { 1, 2 }, { 3, 4 } };
// Declaration 2
int[,] arr = new int[2, 2] { { 1, 2 }, { 3, 4 } };
Which statement accurately describes the difference between these two declarations?
Declaration 1 implicitly sets the dimensions of the array and Declaration 2 explicitly
sets the dimensions of the array.
Declaration 1 defines the fixed size of the array while the size of the Declaration 2 array
can expand at run-time.
Declaration 1 explicitly sets the dimensions of the array and Declaration 2 implicitly sets
the array dimensions.
Declaration 1 allows the size of the array to be changed at run-time and Declaration 2
explicitly sets the dimensions of a jagged array.
I don't know yet.
General Information
It can encapsulate properties in the record.
It can extract properties from the record.
It makes properties accessible, even if the record is marked as sealed.
I don't know yet.
37. What change can you make to the following abstract class to eliminate the syntax error?
Remove the line of code inside the eatFood() method.
Add a method body to the makeSound() method.
Add a method body to the sleep() method.
Update the isSleeping() method to either public or private.
I don't know yet.
38. What will the value of fact2 be after this code executes?
string fact = "Life is too short to...always remove the USB drive safely";
40. The following code results in a compilation error. What must you change to correct this error?
public class TestAction1
{
public static void Main()
{
Action<T> messageTarget;
if (Environment.GetCommandLineArgs().Length > 1
messageTarget = ShowWindowsMessage;
else
messageTarget = Console.WriteLine;
General Information
messageTarget("Hello, World!");
}
private static void ShowWindowsMessage(string message)
{
MessageBox.Show(message);
}
}
1.
class MyClass {
private static DailyTemperature[] tempData = new DailyTemperature[] {
new DailyTemperature(high: 57, low: 30),
new DailyTemperature(60, 35),
new DailyTemperature(63, 33)
};
public static void Main(string[] args) {
tempData[1].high = 30;
}
}
Why won't this code compile?
Unshort
3. There are multiple tasks from a single thread and you must propagate any exceptions back to
the calling thread, handling each exception individually. How can you do so?
General Information
4. You created the following positional record:
public record Person(string FirstName, string LastName);
Given this positional record, how can you construct a new Person?
5. How many times does the first statement (int i = 0;) of this for loop execute?
for (int i = 0; i < 5; i++) {
//do stuff
}
6.
7.
General Information
The publisher determines when an event is raised; the subscribers determine what action
is taken in response to the event.
8.
Allows types in the System namespace to be referenced without specifying the namespace
explicitly
9.
10.
The following try/catch block results in the loss of the current stack trace, and a new stack trace
is started at the current method:
try {
//try statements
} catch (Exception e) {
throw e;
}
What change can you make to preserve the entire stack trace?
11.
General Information
Console.WriteLine("Success!");
else
Console.WriteLine("File write operation failed.");
}
12.
13.
14.
How would you use XML documentation for the following attributes?
General Information
/// <summary>
/// Returns the squared value of an integer value
/// </summary>
/// <param name="intX">number to be squared</param>
15.
You can create a record as a reference type instead of which other construct?
16.
17.
18.
General Information
In this code example, what type of class is Student?
class Class {
private List<Student> _students = new List<Student>();
return total;
}
nested
19.
A derived class is the class that inherits from another class and a base class is the class being
inherited from.
20.
General Information
What is a difference between an interface and an abstract class?
What is the difference between the behavior of the following two pieces of code?
catch(Exception e)
{
throw;
}
and
catch(Exception e)
{
throw e;
}
throw creates a new exception instance, whereas throw e reuses e.
throw reuses e, whereas throw e creates a new exception instance.
General Information
throw does not preserve the stack trace of the originating exception, whereas throw e does.
throw preserves the stack trace of the originating exception, whereas throw e does not.
I don't know yet.
You wrote a class called EmployeeList that encapsulates a list of Employee instances. You want to write
an indexer to obtain an Employee instance from the list by specifying the integer index of the required
employee. What is the correct syntax for declaring the indexer?
public Employee this [int index] { ... }
public Employee operator [] (int index) { ... }
public Employee this[] (int index) { ... }
public static Employee operator [] (int index) { ... }
I don't know yet.
General Information
bool test = Object.ReferenceEquals(greet,copy);
Console.WriteLine ($"{copy} {test}");
Hello True
World False
Hello False
World True
I don't know yet.
What change can you make to remove the syntax error in the following class?
public class Car {
private static int numWheels;
private string type;
Which change would you apply to the following interface to remove the syntax error?
interface Interface1 {
private record iRecord;
private static void display1(int i) { }
public static string display1() {
return "";
}
public abstract void display2() { }
}
Delete the iRecord.
Remove the method body of the display2() method and replace it with a semicolon.
Remove the line of code inside the second display1() method.
Rename the first display1() method to something unique.
I don't know yet.
General Information
You created a positional record as follows:
public record Person(string FirstName, string LastName);
How can you invoke a positional deconstructor on this record?
record person = new Person();
var (p, l) = person;
var person = new Person("User", "One");
var person(p, l);
I don't know yet.
You must cancel a Threading.Task that is running. From which class should you call its
associated Cancel method to do this?
System.Threading.CancellationTokenRegistration
System.Threading.Tasks.Task
System.Threading.CancellationTokenSource
System.Threading.Tasks.TaskCanceledException
I don't know yet.
What sequence of characters indicates the start of an XML-style documentation comment in C# code?
///
<!--
//
/*
I don't know yet.
General Information
public static void Display(long x)
{
Console.WriteLine("Long: " + x);
}
}
What will the following code do?
short value = 10;
NumberWriter.Display(value);
Not compile because the call to Display is ambiguous.
Display Integer: 10.
Throw a RuntimeBinderException because the call to Display is ambiguous.
Display Long: 10.
I don't know yet.
The following code results in a compilation error. What must you change to correct this error?
public class TestAction1
{
public static void Main()
{
Action<T> messageTarget;
if (Environment.GetCommandLineArgs().Length > 1)
messageTarget = ShowWindowsMessage;
else
messageTarget = Console.WriteLine;
messageTarget("Hello, World!");
}
private static void ShowWindowsMessage(string message)
{
MessageBox.Show(message);
}
}
Replace Action<T> messageTarget with Action<string> messageTarget.
Replace private static void ShowWindowsMessage(string message) with
private Action<void> ShowWindowsMessage(string message).
Replace private static void ShowWindowsMessage(string message) with private string
ShowWindowsMessage(string message).
Replace Action<T> messageTarget with Func<bool> messageTarget.
I don't know yet.
General Information
What must x satisfy if this code is to compile?
lock (x)
{
SaveChanges();
}
It must be of type Monitor or Mutex.
It must be an instance of a reference type.
It must be an instance class member.
It must implement IDisposable.
I don't know yet.
When looking for an item in a List, which method would result in a syntax error?
BinarySearch
Search
Contains
Find
I don't know yet.
class MyClass {
private static DailyTemperature[] tempData = new DailyTemperature[] {
new DailyTemperature(high: 57, low: 30),
new DailyTemperature(60, 35),
new DailyTemperature(63, 33)
};
public static void Main(string[] args) {
tempData[1].high = 30;
}
}
General Information
tempData[1].high is immutable, so it can only be set at object initialization, not in
the main method.
General Information
}
}
Which class correctly demonstrates a class inheriting the class Automobile?
public class Car : Automobile(1, Color.Red)
{
}
public class Car : Automobile()
{
private Automobile auto = new Automobile(1, Color.Red);
}
public class Car : Automobile
{
}
public class Car
{
private Automobile auto = new Automobile(1, Color.Red);
}
I don't know yet.
Which keyword would you use to pass a value-type instance by reference in a method?
ByReference
ByRef
ref
reference
I don't know yet.
You use an interface named IService to inject different implementations into a system. When the
following code is compiled an error is returned, however.
1. public interface IService<T> { }
2. public class ServiceA : IService<int> {}
3. public class ServiceB : IService<String> {}
4. public class ServiceC : IService<>() {}
Which line is the cause of the error?
3
4
1
2
General Information
return _firstName + " " + _lastName;
}
When this code is compiled there is an error. What must be changed to correct this problem?
Add _firstName and _lastName as parameters for the method
Change the access level from public to private
Return the value using get; and set;
Change the return type from void to string
I don't know yet.
switch (caseSwitch){
case 1:
Console.WriteLine("Case 1");
break;
case 2:
Console.WriteLine("Case 2");
break;
case 3:
Console.WriteLine("Case 3");
break;
default:
Console.WriteLine("Case default");
break;
}
Case 3
Case 2
Case 1
Case default
I don't know yet.
What is a constructor?
A method for initializing an interface or an abstract class
A special reference to a group of constants
A field or method inside a class
A method for initializing an object
I don't know yet.
General Information
Which component of a C# application acts as the entry point?
The class declaration
The declaration of namespace
The Main method
The first class instantiation
I don't know yet.
General Information
You are creating a program that generates a random number between 1 and 10 as follows:
int num = new Random().Next(1, 11);
The output displays the class of the number based on the following criteria:
- Less than 3: Low number
- Between 3 and 6: Middle number
- Between 7 and 9: High number
- 10: 10
How would the associated if statement look for this criteria?
if (num <= 3)
Console.WriteLine("Low number");
else if (num >= 3 || num <= 6)
Console.WriteLine("Middle number");
else if (num > 6 || num < 10)
Console.WriteLine("High number");
else
Console.WriteLine("10");
if (num <= 3)
Console.WriteLine("Low number");
else if (num == 3 || num <= 7)
Console.WriteLine("Middle number");
else if (num == 8 || num < 10)
Console.WriteLine("High number");
else
Console.WriteLine("10");
if (num < 3)
Console.WriteLine("Low number");
else if (num >= 3 && num <= 6)
Console.WriteLine("Middle number");
else if (num > 6 && num < 10)
Console.WriteLine("High number");
else
Console.WriteLine("10");
if (num < 3)
Console.WriteLine("Low number");
else if (num > 3 && num < 6)
Console.WriteLine("Middle number");
else if (num >= 6 && num <= 10)
Console.WriteLine("High number");
else
Console.WriteLine("10");
I don't know yet.
General Information
What will be the results of the following expression if zero is an int and contains the value 0?
int zero = 0;
int x = 100 / zero;
It will throw DivideByZeroException.
It will return int.PositiveInfinity.
It will return int.NaN.
It will throw an unknown error exception.
I don't know yet.
Which keyword would you use to create an object?
class
new
create
var
I don't know yet.
Assuming today's date is January 1, 2025, what will the following format return?
string formattedDate = DateTime.Now.ToString("dddd, dd MMMM");
Wednesday, 01 January
Wed, 01 Jan
Wednesday, 1 Jan
3, 01 01
I don't know yet.
A try block surrounds a block of your code. You must run a few lines of code to close some
streams and database calls whether an exception is thrown or not. How can you ensure that this
code runs?
Add a break statement at the end of the try block.
Add a finally block between the try and catch block.
Add a break statement at the end of the catch block.
Add a finally block after the catch block.
I don't know yet.
Consider the following interfaces and class that implements both interface I1 and I2:
interface I1
{
void A();
}
interface I2
{
void A();
}
class C : I1, I2
{
public void A()
{
Console.WriteLine("C.A()");
General Information
}
}
Which statement is true regarding A()?
A() can only be invoked through the I1 or I2 interfaces explicitly.
A() is a public class member that implicitly implements a member of both
interfaces.
A() is a public class member that explicitly implements a member of both
interfaces.
A() can be invoked only through the class itself.
I don't know yet.
What does ~0 (the number zero with a tilde symbol in front of it) evaluate as?
int.MaxValue
-1
255
True
I don't know yet.
If you define a class or struct, C# sometimes provides a default parameterless constructor. When
does this happen?
Whenever the class or struct does not define a parameterless constructor
explicitly
Only if no constructors are explicitly defined
Always for a struct; for a class, only if no constructors are explicitly defined
Only for structs, never for classes
I don't know yet.
How would you remove the third element in the following array?
General Information
Book[] bookArray = {
new Book() { Id = 1, Category = "Fiction", PubYear = 1997 },
new Book() { Id = 2, Category = "Bios & Memoirs", PubYear = 2015 },
new Book() { Id = 3, Category = "Business", PubYear = 2015 },
new Book() { Id = 4, Category = "Classics" , PubYear = 1962 },
new Book() { Id = 5, Category = "History" , PubYear = 2001 },
new Book() { Id = 6, Category = "Fiction", PubYear = 2001 },
new Book() { Id = 7, Category = "Bios & Memoirs", PubYear = 1997 }
};
bookArray.RemoveAt(2);
bookArray = bookArray.Where((source, index) => index != 2).ToArray();
bookArray.RemoveAt(3);
int posToRemove = 2;
for (int i = posToRemove - 1; i < bookArray.Length-1; i++) {
bookArray[i] = bookArray[i + 1];
}
I don't know yet.
Which types of parameters support covariance and contravariance to provide greater flexibility in
assigning and using generic types?
Generic interfaces, delegates, and classes
Generic interfaces and delegates
Generic interfaces, classes, and structs
Generic classes and structs
I don't know yet.
Which method finds the difference in days as an integer between two dates?
var numOfDays = DateTime.DateDiff(date1,date2,Days);
var numOfDays = date1.Subtract(date2).Days;
var numOfDays = (date1 - date2).TotalDays;
var numOfDays = DateTime.Subtract(date1,date2,Days);
I don't know yet.
General Information
var persony = new Person { FirstName = "First", LastName = "Last" };
if (personx == persony)
System.Diagnostics.Debug.WriteLine("equal");
else
System.Diagnostics.Debug.WriteLine("not equal");
if (personx.Equals(persony))
System.Diagnostics.Debug.WriteLine("equal");
else
System.Diagnostics.Debug.WriteLine("not equal");
}
}
not equal
not equal
equal
not equal
not equal
equal
equal
equal
I don't know yet.
You have two types, ClassA and ClassB. Inside which types could you define a custom implicit
type conversion from ClassA to ClassB?
ClassA or ClassB
ClassA or ClassB or any class that inherits from either ClassA or ClassB
ClassA or any class that inherits from A
Only ClassA
I don't know yet.
General Information
bookArray.Add(book);
bookArray.Add(book2);
Resize the array before adding the new books:
Array.Resize(ref bookArray, bookArray.Length + 2);
Resize the array before adding the new books:
bookArray.Resize(bookArray.Length + 2);
Use the AddRange() method instead:
bookArray.AddRange(book, book2);
I don't know yet.
User code running inside a task propagated back to a calling thread is throwing unhandled
exceptions. Which approach can you use to get access to an unhandled exception before it is
thrown?
The AggregateException.Handle method
The AggregateException.Flatten method
The Task.Exception method
The Task.Wait method
I don't know yet.
6.
Correct -
Method syntax requires you to use anonymous classes for the rest of
the query, whereas query syntax allows you to use the let keyword with
no restrictions.
Incorrect -
General Information
Your choice: incorrect -
Method syntax allows you to use the let keyword with no restrictions,
whereas the query syntax requires you to use anonymous classes for
the rest of the query.
Incorrect -
Method syntax only allows you to use one OrderBy() method in a query,
whereas query syntax allows you to use multiple orderby statements in
the same query.
Incorrect -
8.
Incorrect -
System.Threading.CancellationTokenTask
Correct -
System.Threading.CancellationTokenSource
General Information
Your choice: incorrect -
System.Threading.CancellationToken
Incorrect -
System.Threading.Tasks.CancellationTokenSource
Incorrect -
9.
Correct -
Incorrect -
General Information
Your choice: incorrect -
Incorrect -
Incorrect -
14.
Correct -
Incorrect -
General Information
Your choice: incorrect -
Incorrect -
Incorrect -
15.
Incorrect -
General Information
The display1() method in Interface2 must be declared overrides.
Incorrect -
Correct -
Incorrect -
16.
Which is the correct Event Handler to use when declaring an event called
ReturnClicked?
Incorrect -
General Information
public event EventHandler ReturnClicked(object sender,
EventArgs e);
Incorrect -
Correct -
Incorrect -
18.
}
}
How do you begin running taskA?
General Information
Incorrect -
if (taskA.Exists)
{
taskA.Start();
}
taskA.Run()
Incorrect -
Correct -
taskA.Start();
Incorrect -
1.
General Information
The variable i is declared and then initialized in the following for loop. What
value will the following code display on the console?
int i;
for (i = 0; i < 10; i++)
{
}
Console.WriteLine(i);
Incorrect -
Incorrect -
Correct -
10
Incorrect -
2.
General Information
The following using directives have been added to a class. What is the
purpose of adding directives?
using System;
using System.Data;
using System.Linq;
using System.Text;
Incorrect -
Correct -
Incorrect -
Incorrect -
3.
General Information
A C# application requires a connection to an associated database. When
setting up a connection with the SqlConnection class, you want the scope
of the connection variable to live only until the connection is closed. How can
you do this?
Incorrect -
Import the namespace at the top of the file with a using statement:
using System.Data.SqlClient;
Incorrect -
Incorrect -
Declare the connection in the application settings and call it in the code.
var connection = Properties.Settings.Default.connection;
Incorrect -
4.
General Information
Which method is the safest way to convert an unknown string value to a
numeric value?
Correct -
Incorrect -
Convert.ToInt32(someValue);
if(someValue.ToString()){
someValue = 0;
}
else if (someValue.ToInt32){
someValue = Convert.ToInt32(someValue);
}
else{
someValue = null;
}
Incorrect -
try{
return Convert.ToInt32(someValue);
}
General Information
catch(Exception ex)
return ex.Message;}
Incorrect -
5.
Incorrect -
Incorrect -
Incorrect -
General Information
Incorrect -
6.
Incorrect -
Correct -
Incorrect -
Incorrect -
General Information
I don't know yet.
7.
Incorrect -
Incorrect -
Classes without constructors require the keyword new before they can be
instantiated as an object.
Incorrect -
Incorrect -
8.
General Information
Your choice: incorrect -
Incorrect -
Correct -
Incorrect -
Incorrect -
9.
Given the following class, which line of code would create an instance of this
class and set the new instance's attributes?
public class Table{
string _color;
int _width;
int _height;
public Table(string color, int width, int height){
this._color = color;
this._width = width;
General Information
this._height = height;
}
}
Incorrect -
Incorrect -
Incorrect -
Incorrect -
10.
General Information
Which line of code is an example of instantiating a Dictionary<TKey,
TValue> without adding initial values?
Correct -
Incorrect -
Incorrect -
Incorrect -
11.
General Information
1997 },
new Book() { Id = 2, Category = "Bios & Memoirs",
PubYear = 2015 },
new Book() { Id = 3, Category = "Business", PubYear =
2015 },
new Book() { Id = 4, Category = "Classics" , PubYear =
1962 },
new Book() { Id = 5, Category = "History" , PubYear =
2001 },
new Book() { Id = 6, Category = "Fiction", PubYear =
2001 },
new Book() { Id = 7, Category = "Bios & Memoirs",PubYear
= 1997 }
};
How can you create a new list that contains all unique PubYears?
Incorrect -
Incorrect -
Incorrect -
General Information
var bookId = bookArray.Select(x => x.PubYear);
Incorrect -
12.
What happens to the resource variable once the following code executes?
using (MyExternalResource resource = new
MyExternalResource()) {
resource.DoStuff();
}
Correct -
Incorrect -
Incorrect -
The garbage collector will temporarily dispose of it, but it will still be
available for reuse.
General Information
Incorrect -
13.
You have the following string declaration and want to throw an exception if it is
empty. Which line of code would represent the correct way to throw an
exception?
string str = "";
//series of if statements to set the value of str
if (string.IsNullOrEmpty(str)) {
//answer here
}
Incorrect -
Incorrect -
Incorrect -
General Information
Incorrect -
14.
Incorrect -
Correct -
General Information
Incorrect -
Incorrect -
15.
Incorrect -
General Information
Incorrect -
Incorrect -
Incorrect -
16.
Incorrect -
Incorrect -
Incorrect -
General Information
public class Class1<out>
Incorrect -
17.
Incorrect -
General Information
Incorrect -
Incorrect -
Incorrect -
18.
General Information
else
Console.WriteLine("10");
switch (num) {
case 1: case 2:
Console.WriteLine("Low number");
break;
case 3: case 4: case 5: case 6:
Console.WriteLine("Middle number");
break;
case 7: case 8: case 9:
Console.WriteLine("High number");
break;
default:
Console.WriteLine("10");
break;
}
Incorrect -
switch (num) {
case 1 || case 2:
Console.WriteLine("Low number");
break;
case 3 || case 4 || case 5 || case 6:
Console.WriteLine("Middle number");
break;
case 7 || case 8 || case 9:
Console.WriteLine("High number");
break;
default:
Console.WriteLine("10");
break;
}
Incorrect -
General Information
switch (num) {
case 1: case 2:
Console.WriteLine("Low number");
break;
case 3: case 4: case 5: case 6:
Console.WriteLine("Middle number");
break;
case 7: case 8: case 9:
Console.WriteLine("High number");
break;
else:
Console.WriteLine("10");
break;
}
Incorrect -
switch (num) {
case 1: case 2:
Console.WriteLine("Low number");
case 3: case 4: case 5: case 6:
Console.WriteLine("Middle number");
case 7: case 8: case 9:
Console.WriteLine("High number");
default:
Console.WriteLine("10");
}
Incorrect -
19.
General Information
{
ID = 0; //default id
}
protected int GetNextID()
{
return ++currentId;
}
}
Incorrect -
Incorrect -
Incorrect -
General Information
Your choice: correct -
Incorrect -
20.
Correct -
General Information
Incorrect -
Incorrect -
Incorrect -
General Information