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.
Yes, you can return multiple values from a function using the following approaches:
- ref / out parameters
- Struct / Class
"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
- Can be assigned values only at the time of declaration
- Static by default
- Known at compile time
- Must have set value, by the time constructor exits
- Are evaluated when instance is created
- 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
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# Frequently Asked Questions - 1
- C# Frequently Asked Questions - 3
- Difference between a Debug and Release build
- Difference between normal DLL and .Net DLL
- What is an Interface in C#
- Difference between Abstract Class and Interface
- Difference between a thread and a process
- What is .Net Delegates
- Differences between a control and a component
- Differences between Stack and Heap
- What is .Net Reflection
- Globalization and Localization
- What is .Net serialization
- Difference between web service and .net remoting
- Difference between managed and unmanaged code
- Difference between Shallow copy and Deep copy
- Use of System.Environment Class
- What is the difference between private and shared assembly?
- Does the .NET have in-built support for serialization?
- How to properly stop the Thread in C#?
- Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
- Why is XmlSerializer so slow?
- How many types of Jit Compilers?