SiteMap  | About    

C# Frequently Asked Questions - 3

Please click on the questions to see the answers

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 Security

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.

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.

Mat.floor() will always round down and Math.Truncate rounds towards zero.

In an unsafe context, a type may be a pointer type.

The following types may be a pointer type:

  1. sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.

  2. Any enum type.

  3. Any pointer type.

  4. Any user-defined struct type that contains fields of unmanaged types only.

An assembly is the smallest unit of execution in .Net

With the help of Boxing and UnBoxing you can convert any value type to reference type.



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.

Yes - XML is case sensitive

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.

It is a feature of modern operating systems with which we can run multiple programs at same time example Word, Excel etc.

"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.

In order to output "{" in string.Format you have to escape it like this {{ and to output a "}" you can use }}.

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.

In C# you use the "sealed" keyword in order to prevent a class from being inherited. In VB.NET you use the "NotInheritable" keyword.

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.

Constructors can be divided into 5 types:

  1. Default constructor
  2. Parameterized constructor
  3. Instance constructor
  4. Static constructor
  5. Private constructor

Both are same, bool is an alias for System.Boolean.

You can assign a Boolean value to a bool variable.

Array store only single datatype. If you want to store different types, use System.Collections.ArrayList or object[]

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 types

  1. Single Dimension Arrays
  2. Multi-Dimensional Arrays
  3. Jagged Arrays

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.

No, because there are no checked exceptions 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.

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) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.