Skip to main content

What are the Differences between the Debug class and Trace class?

Debug and Trace both classes are included in Systems.Diagnostics namespace and have very similar methods. The main difference is that call to Debug class is included in Debug mode only while call to Trace class will be included in Debug as well as Release mode also.

So in short we can say it is advisable to use Debug at the time of application development, while Trace option is used at the time of application deployment, like we can trace any error and write it into log files etc.

What is the differences between a Debug and Release build?

When we are building any .Net project there are two configuration we can select 1 is Debug and another is for Release, While we are developing an application default mode is Debug and programmers keeps is Debug mode for debugging code step by step or line by line. Once project is completed we need to change it to Release mode before generating final build like DLL, EXE or published code.

The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure out where it is in the source code.

Normally Debug builds are not optimized and it has debugging symbols, while the code build in the Release mode is more optimized, It is very less in size and more faster then Debug mode.

What is the role of .pdb files ?
PDB is stands for Program Database File, it contains the debug information about the application depending on the compiler option that we have used. It holds application state information and debugging information that allows incremental linking of a Debug configuration of out application. PDB file is created when we are running a C# application in Debug mode.

We can set the debug mode in web.config file as shown below

// For Debug mode

<system.web>
<compilation debug="true">

or

// For Release mode

<system.web>
<compilation debug="false">

Happy Debugging

C# interview question answers

Q-1: Which of the following statement is true?
a. try block must be followed by catch and finally block both.
b. try block must be followed by catch or finally block or both.
c. try block cannot include another try block.
d. All of the above.

Correct Answer: (b) try block must be followed by catch or finally block or both.

Q-2: Which of the following datatype can be used with enum?
a. Int
b. String
c. Boolean
4. All of the above

Correct Answer: (a) Int

Q-3: A partial class allows ________
a. Implementation of single class in multiple .cs files.
b. Declaration of multiple classes in a single .cs file.
c. Implementation of multiple interfaces to single class.
d. Multiple class inheritance.

Correct Answer: (a) Implementation of single class in multiple .cs files.

Q-4: C# class can inherit multiple ________
a. Class
b. Interface
c. Abstract class
d. Static class

Correct Answer: (b) Interface

Q-5: Struct is a _____.
a. Reference type
b. Value type
c. Class type
d. String type

Correct Answer: (b) Value type

Q-6: Which of the following is true for ReadOnly variables?
a. Value will be assigned at runtime.
b. Value will be assigned at compile time.
c. Value will be assigned when it accessed first time
d. None of the above

Correct Answer: (a) Value will be assigned at runtime.

Q-7: LINQ stands for ________.
a. Language Integrated Query
b. Local Integration Query
c. Language Included Query
d. Lazy Integrated Query

Correct Answer: (a) Language Integrated Query

Q-8: Which of the following is true for dynamic type in C#?
a. It allows multiple time declaration of a variable.
b. It allows compile time type checking
c. It escapes compile time type checking
d. None of the above.

Correct Answer: (c) It escapes compile time type checking

Q-9: String data type is ______.
a. Mutable
b. Immutable
c. Static
d. Value type

Correct Answer: (b) Immutable

Q-10: Which of the following is right way of declaring an array?
a. Int[] intArray = new int[];
b. Int intArray[] = new int[5];
c. Int[] intArray = new int[5];
d. Int[] intArray = new int[]{1, 2, 3, 4, 5};

Correct Answer: (c) Int[] intArray = new int[5];

Q-11: What is Nullable type?
a. It allows assignment of null to reference type.
b. It allows assignment of null to value type.
c. It allows assignment of null to static class.
d. None of the above.

Correct Answer: (b) It allows assignment of null to value type.

Q-12: Which of the following is a reference type in C#?
a. String
b. Long
c. Boolean
d. None of the above

Correct Answer: (a) String

Q-13: Data type of a variable declared using var will be assigned at _______.
a. Runtime
b. Compile time
c. CLR time
d. Application Initialization time.

Correct Answer: (b) Compile time

Q-14: 10 > 9 ? “10 is greater than 9” : “9 is greater than 10” is an example of _______
a. Ternary operator
b. Conditional operator
c. Greater than operator
d. Inverse operator

Correct Answer: (a) Ternary operator

Q-15: Which of the following statement is true?
a. A finally block may not execute every time
b. A finally block cannot include return or break keyword.
c. A finally block can come before catch block.
d. Multiple finally block is possible.

Correct Answer: (b) A finally block cannot include return or break keyword.

Q-16: What is indexer?
a. It allows an instance of a class to be indexed like an array
b. It allows enumerator with class
c. It creates index for instances of a class.
d. None of the above.

Correct Answer: (a) It allows an instance of a class to be indexed like an array

Q-17: Return type of Predicate <T>() is always a ______.
a. Integer
b. String
c. Boolean
d. Void

Correct Answer: (c) Boolean

Q-18: An array in C# starts with _____ index.
a. One
b. Zero
c. -1
d. None of the above

Correct Answer: (b) Zero

Q-19: Which of the followings are value types in C#?
a. Int32
b. Double
c. Decimal
d. All of the above

Correct Answer: (d) All of the above

Q-20: Func and Action are the types of ______.
a. Utility function
b. Delegate
c. Event
d. Generic class

Correct Answer: (b) Delegate