0% found this document useful (0 votes)
197 views5 pages

Interview Questions - C# - Developer

The document discusses various C# coding concepts: 1. Exception handling requirements can be met by logging exceptions using the LogException() method and rethrowing the original exception including the stack. 2. When accessing an object's properties through an interface, the "as" keyword can be used to avoid exceptions if the object is not of that interface type. 3. A Queue can be used to store a collection of Order objects that must be processed in FIFO order, store values, and use zero-based indices. 4. To access the executing assembly in a console application, use Assembly.GetExecutingAssembly(). 5. A for loop can be used when iterating over a collection

Uploaded by

Phani Prudhvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
197 views5 pages

Interview Questions - C# - Developer

The document discusses various C# coding concepts: 1. Exception handling requirements can be met by logging exceptions using the LogException() method and rethrowing the original exception including the stack. 2. When accessing an object's properties through an interface, the "as" keyword can be used to avoid exceptions if the object is not of that interface type. 3. A Queue can be used to store a collection of Order objects that must be processed in FIFO order, store values, and use zero-based indices. 4. To access the executing assembly in a console application, use Assembly.GetExecutingAssembly(). 5. A for loop can be used when iterating over a collection

Uploaded by

Phani Prudhvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. You are developing an application that uses structured exception handling. The application includes a class named ExceptionLogger.

r. The
ExceptionLogger class implements a method named LogException by using the following code segment:
public static void LogException(Exception ex)

You have the following requirements


a. Log all exceptions by using the LogException() method of the ExceptionLogger
class.
b. Rethrow the original exception, including the entire exception stack.

You need to meet the requirements. Which code segment should you use?

Answer – A
2. You are developing an application by using C#. The application includes the following code segment. (Line numbers are included for
reference only.)

The DoWork() method must not throw any exceptions when converting the obj object to the IDataContainer interface or when
accessing the Data property.
You need to meet the requirements. Which code segment should you insert at line 07?

a. var dataContainer = (IDataContainer)obj;


b. dynamic dataContainer = obj;
c. var dataContainer = obj is IDataContainer;
d. var dataContainer = obj as IDataContainer;

Answer - D
3. You are developing an application that includes a class named Order. The application will store a collection of Order objects.
The collection must meet the following requirements:
> Use strongly typed members.
> Process Order objects in first-in-first-out order.
> Store values for each Order object.
> Use zero-based indices.
You need to use a collection type that meets the requirements. Which collection type should you use?

a.  Queue<T>
b.  SortedList
c.  LinkedList<T>
d.  HashTable
e.  Array<T>

Answer : A

4. You are creating a console application by using C#. You need to access the application assembly.
Which code segment should you use?
a.  Assembly.GetAssembly(this);
b.  this.GetType();
c.  Assembly.Load();
d. Assembly.GetExecutingAssembly();

Answer - D

5. You need to iterate over a collection in which you know the number of items. You need to remove certain items from the collection.
Which statement do you use?
a. switch
b. foreach
c. for
d. goto
answer – C
6. A class inherits a base class and it overrides a method from that base class.Select all possible forms of the base class and its method:
a. The base class can be sealed in C# (NotInheritable in Visual Basic).
b. The base class can be abstract in C# (MustInherit in Visual Basic).
c. The method from the base class can be abstract in C# (MustOverride in Visual Basic).
d. The method from the base class can be virtual in C# (Overridable in Visual Basic).
e. The method from the base class does not need to have any modifier.
f. The method from the base class can have only a protected modifier.
g. The method in the overriding class must have the override (Overrides in Visual Basic).
Answer – b, c, d, g

7. Select all the methods that can be used to pass data from the controller to the view.

a. By setting properties on the model that is passed to the view.

b. By setting properties on the web controls that the view contains.

c. By using the view's helper methods.

d. By using ViewData dictionary.

Hint 1: The ViewBag and TempData objects are visible to the model and the view.

Answer – a, d
8. Which of these statements are true for bundling in ASP.NET Web Forms?

a. By default, bundling is disabled in debug mode.


b. A link produced by <webopt:bundlereference runat="server" path="~/Content/css" /> will be constant through the
project lifetime.

c. There are different classes for minifying JavaScript and for minifying CSS.

d. Bundling will set Cache-Control to no-cache.

e. Bundle.Include(virtualPath) method can accept some forms of wildcard (*) syntax.

Hint 1: Bundling makes it easy to combine multiple files.


Answer – a, c, e

9.
public class UserController: Controller {
[Route("/user")]
public IActionResult GetUser() {
return Content("Ask for specific user on URL: /user/{userId}");
}[Route("/user/{userId}")] public IActionResult GetUserById(string userId) {
return Content($ "User with id: {userId}");
}
}

Select which of the following URLs that will be routed to the GetUserById method.

a. /user/someid

b. /user/user/1

c. /user/123

d. /user/21id

e. /user/name/password

f. /user/

Hint 1: The parameter in the URI template will match to the next slash.
Answer – a, c,d

10. Which statements are true for an int/Integer built in .NET data type?
a. It supports bitwise operators.
b. On a 64bit system, it can contain the number 2^48.
c. The ToString method can be used for formatting a numerical value.
d. The expression a/b will return infinity if a has value 1 and b has value 0.
e. It is unsigned by default and does not support negative values.
Answer – a, c

11. Choose the correct output for the C#.NET code given below?
enum days: int {
sunday = -3,
monday,
tuesday
}
Console.WriteLine((int) days.sunday);
Console.WriteLine((int) days.monday);
Console.WriteLine((int) days.tuesday);
a) 3 0 1
b) 0 1 2
c) -3 -2 -1
d) sunday monday Tuesday

Answer: c
12. What will be the output for the given set of code?
1. namespace ConsoleApplication4
2. {
3. abstract class A
4. {
5. int i;
6. public abstract void display();
7. }
8. class B: A
9. {
10. public int j;
11. public override void display()
12. {
13. Console.WriteLine(j);
14. }
15. }
16. class Program
17. {
18. static void Main(string[] args)
19. {
20. B obj = new B();
21. obj.j = 2;
22. obj.display();
23. Console.ReadLine();
24. }
25. }
26. }

a) 0
b) 2
c) Compile time error
d) 1
Answer - b

13. If a class inheriting an abstract class does not define all of its functions, then it is known as?
a) Abstract
b) A simple class
c) Static class
d) None of the mentioned
Answer -a
14. Select the correct output for the given set of code?

class sample {
public int i;
void display() {
Console.WriteLine(i);
}
}
class sample1: sample {
public int j;
public void display() {
Console.WriteLine(j);
}
}
class Program {
static void Main(string[] args) {
sample1 obj = new sample1();
obj.i = 1;
obj.j = 2;
obj.display();
Console.ReadLine();
}
}
a) 1
b) 3
c) 2
d) Compile Time error

Answer - C

15. The modifier used to hide the base class methods is?
a) Virtual
b) New
c) Override
d) Sealed

Answer - d

You might also like