SiteMap  | About    

C# Frequently Asked Questions - 2

Please click on the questions to see the answers

Object pool is used to track the objects which are being used in the code. So object pool reduces the object creation overhead.

Static constructor is used to initialize static data members as soon as the class is referenced first time.

"this" represents the current class instance while "base" the parent.

System.Exception class is the base class for all exceptions.

In C# there is a "try… catch" block to handle the exceptions.

The reason for the "using" statement is to ensure that the object is disposed as soon as it goes out of scope, and it doesn't require explicit code to ensure that this happens. Using calls Dispose() after the using-block is left, even if the code throws an exception.

A collection works as a container for instances of other classes. All classes implement ICollection interface.

Yes, it is possible to have try block without catch block by using finally block. The "using" statement is equivalent try-finally.

You put an @ sign in front of the double-quoted string.

No. Once any exception is occurred it executes specific exception catch block and the control comes out.

The data value may not be changed.

Reflection allows us to get metadata and assemblies of an object at runtime.

System.Globalization, System.Resources.

Yes, you can return multiple values from a function using the following approaches:

  1. ref / out parameters
  2. Struct / Class
  3. Tuple

"ref" tells the compiler that the object is initialized before entering the function, while "out" tells the compiler that the object will be initialized inside the function.

A Value Type holds the data within its own memory allocation and a Reference Type contains a pointer to another memory location that holds the real data. That means, Value type holds some value only and not hold memory addresses and Reference types holds a memory address of a value.

More about.... value types and reference types


  1. Can be assigned values only at the time of declaration
  2. Static by default
  3. Known at compile time
Read only
  1. Must have set value, by the time constructor exits
  2. Are evaluated when instance is created
  3. Known at run time



The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET assemblies that are specifically designated to be shared by all applications executed on a system.

By default you could see all assemblies installed in GAC in

c:\windir\assembly folder

System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arise.

See more.... How to force Garbage Collection

See more... What is Garbage Collection

XmlSerializer will refuse to serialize instances of any class that implements IDictionary.

Obfuscate your code. Dotfuscator has a free edition and comes with Visual Studio. These tools work by "optimising" the IL in such a way that reverse-engineering becomes much more difficult. Also host your service in any cloud service provider that will protect your IL from reverse-engineering.

The configuration file is really only for settings configured at deployment time. It can be used to deal with versioning issues with .NET components. And it's often used for connections strings - it's useful to be able to deploy an application to connect to a test or staging server, but this is not something you'd normally change in production once the application is deployed.

Value types get stored on stack and shared the same process memory, however the Reference Types get stored on Heap and their memory address value gets stored on the stack as value type.


A formatter is an object that is responsible for encoding and serializing data into messages on one end, and deserializing and decoding messages into data on the other end.

One DLL can contains Unlimited classes.

It is the metadata that describes the assemblies

Both are same. System.Int32 is a .NET class. Int is an alias name for System.Int32. (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.