C# Interview Questions (part-3)
What is code access security (CAS)?
Code Access Security (CAS) is the security sandbox for .NET. Local apps typically have full trust which means they can do anything. The .NET apps that are hosted in the browser can't do much. In between, just about any security setting can be fine-tuned using CAS. More on.... Code Access SecurityWhich is the best place to store connection string in .NET projects?
Web.config and App.config are the best places to store connection strings. If it is a web-based application "Web.config" file will be used and if it is a windows application "App.config" files will be used.What is strong-typing versus weak-typing?
- Strong-typing is compiler enforced declaration and maintenance of variable types such that you do not fall into the trap of performing operation and analysis on types which are incompatible with each other.
- Weak-typing allows ambiguities and maintenance of variable operations is more, so on the coder, opening up possibilities of creating difficult to trap errors.
Difference between Math.Floor() and Math.Truncate()?
Mat.floor() will always round down and Math.Truncate rounds towards zero.What are pointer types in C#?
In an unsafe context, a type may be a pointer type.
The following types may be a pointer type:
- sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
- Any enum type.
- Any pointer type.
- Any user-defined struct type that contains fields of unmanaged types only.
What is the smallest unit of execution in .NET?
An assembly is the smallest unit of execution in .Net
How do you convert a value-type to a reference-type?
With the help of Boxing and UnBoxing you can convert any value type to reference type.
BoxingWhat does the keyword "virtual" declare for a method or property?
The virtual keyword is used to modify a method, property, indexer or event declaration, and allow it to be overridden in a derived class. By default a method cannot be overridden in a derived class unless it is declared virtual, or abstract.Is XML case-sensitive?
Yes - XML is case sensitive
What is the Global.asax used for?
The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level and session-level events raised by ASP.NET or by HTTP modules.What is Multi-tasking?
It is a feature of modern operating systems with which we can run multiple programs at same time example Word, Excel etc.
How can you reference current thread of the method?
"Thread.CurrentThread" refers to the current thread running in the method. Thread.getCurrentThread() is a static method, meaning it does not operate on an instance of Thread but rather on its class.How to escape curly brackets in a format string in C#?
In order to output "{" in string.Format you have to escape it like this {{ and to output a "}" you can use }}.
Is overriding of a function possible in the same class?
No. It is not possible, the override modifier is used to extend the base class method not for hiding method definitions in the current class.How do you prevent a class from being inherited?
In C# you use the "sealed" keyword in order to prevent a class from being inherited. In VB.NET you use the "NotInheritable" keyword.Can a private virtual method be overridden?
No. You can't even declare private virtual methods. Because private methods can ONLY be accessed from the class defining them, hence a private virtual method would be useless.List the types of Constructors in C#?
Constructors can be divided into 5 types:
- Default constructor
- Parameterized constructor
- Instance constructor
- Static constructor
- Private constructor
What is the difference between bool and Boolean types in C#?
Both are same, bool is an alias for System.Boolean.
You can assign a Boolean value to a bool variable.
Can you store multiple data types in System.Array?
Array store only single datatype. If you want to store different types, use System.Collections.ArrayList or object[]Array is reference type or value type ?
Array in .net is of reference type.
All array types are implicitly derived from System.Array, which itself is derived from System.Object . This means that all arrays are always reference typesWhat are different types of an Array ?
- Single Dimension Arrays
- Multi-Dimensional Arrays
- Jagged Arrays
Can finally bock have return statement?
You can't return from finally block. You will get compiler error:
It is a compile-time error for a return statement to occur in a finally block.
Does C# have a throws clause?
No, because there are no checked exceptions in C#.
Can multiple catch blocks be executed in C#?
No, because only one of the exceptions will be thrown. But, you can have multiple catch blocks associated with a try block ,but only a single catch block can ever handle your exception. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed. It doesn't go back into the try block, so you can't end up with a second exception.Will finally block get executed if the exception had not occurred?
The code inside a finally block will get executed regardless of whether or not there is an exception. Also the catch block is only executed if a managed exception is thrown within the associated try block.- C# Interview Questions (part-1)
- C# Interview Questions (part-2)
- 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
- Delegates in C# with Examples
- 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?