Posts

Showing posts from June, 2012

interview questions from net..4

Satellite assemblies are best suited for...........  Application that generate content at runtime or that have large executable components  Which ASP.NET performance counter is the best indicator of inefficient caching?  Turnover rate performance counter  Which is not the element to perform conditional processing with XSL? Correct  How can you detect when application data is about to be removed from the cache? Onremovecallback  XSL transformations convert XML input files to HTML through the XML server control. Correct  The _______________ property determines which satellite assembly is used when loading resources. Correct A web application running on a single server using multiple processors. Choose the best suited option.  Web garden The process of reading database records without locking the records being read.  Dirty Read  How can Garbage Collection be forced in .NET? True In form authentication settings in web.config, which element is used to set the n

inheritance and structure

What are the 4 pillars of any object oriented programming language? 1. Abstraction 2. Inheritance 3. Encapsulation 4. Polymorphism Do structs support inheritance? No, structs do not support inheritance, but they can implement interfaces. What is the main advantage of using inheritance? Code reuse Is the following code legal? class ChildClass : ParentClassA, ParentClassB { } No, a child class can have only one base class. You cannot specify 2 base classes at the same time. C# supports single class inheritance only. Therefore, you can specify only one base class to inherit from. However, it does allow multiple interface inheritance.   What will be the output of the following code? using System; public class BaseClass { public BaseClass() { Console.WriteLine("I am a base class"); } } public class ChildClass : BaseClass { public ChildClass() { Console.WriteLine("I am a child class"); } static void Main() { ChildClass CC = new Ch

access modifiers and abstract, sealed class

What are Access Modifiers in C#? In C# there are 5 different types of Access Modifiers. Public The public type or member can be accessed by any other code in the same assembly or another assembly that references it. Private The type or member can only be accessed by code in the same class or struct. Protected The type or member can only be accessed by code in the same class or struct, or in a derived class. Internal The type or member can be accessed by any code in the same assembly, but not from another assembly. Protected Internal The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly. What are Access Modifiers used for? Access Modifiers are used to control the accessibilty of types and members with in the types. Can you use all access modifiers for all types? No, Not all access modifiers can be used by all types or members in all contexts, and in some cases the accessibility of a type member is constr

polymorphism and fields

What are the 2 broad classifications of fields in C#? 1. Instance fields 2. Static fields What are instance fields in C#? Instance fields are specific to an instance of a type. If you have a class T, with an instance field F, you can create two objects of type T, and modify the value of F in each object without affecting the value in the other object. What is a static field? A static field belongs to the class itself, and is shared among all instances of that class. Changes made from instance A will be visible immediately to instances B and C if they access the field. Will the following code compile? using System; class Area {    public static double PI = 3.14; } class MainClass {    public static void Main()    {       Area A = new Area();       Console.WriteLine(A.PI);    } } No, a compile time error will be generated stating "Static member 'Area.PI' cannot be accessed with an instance reference; qualify it with a type name instead".

constants and why override .tostring() method

What are constants in C#? Constants in C# are immutable values which are known at compile time and do not change for the life of the program. Constants are declared using the const keyword. Constants must be initialized as they are declared. You cannot assign a value to a constant after it isdeclared. An example is shown below. using System; class Circle {    public const double PI = 3.14;    public Circle()    {       //Error : You can only assign a value to a constant field at the time of declaration       //PI = 3.15;    } } class MainClass {    public static void Main()    {       Console.WriteLine(Circle.PI);    } } Can you declare a class or a struct as constant? No, User-defined types including classes, structs, and arrays, cannot be const. Only the C# built-in types excluding System.Object may be declared as const. Use the readonly modifier to create a class, struct, or array that is initialized one time at runtime (for example in a constructor) a

methods and properties

Is the following code legal? using System; namespace Demo {  class Program  {   public static void Main()   {   }   public void Sum(int FirstNumber, int SecondNumber)   {    int Result = FirstNumber + SecondNumber;   }   public int Sum(int FirstNumber, int SecondNumber)   {    int Result = FirstNumber + SecondNumber;   }  } } No, The above code does not compile. You cannot overload a method based on the return type. To overload a method in C# either the number or type of parameters should be different. In general the return type of a method is not part of the signature of the method for the purposes of method overloading. However, it is part of the signature of the method when determining the compatibility between a delegate and the method that it points to. What is the difference between method parameters and method arguments. Give an example? In the example below FirstNumber and SecondNumber are method parameters where as FN and LN are method argument

destructor and constructor

What is a Destructor? A Destructor has the same name as the class with a tilde character and is used to destroy an instance of a class. Can a class have more than 1 destructor? No, a class can have only 1 destructor. Can structs in C# have destructors? No, structs can have constructors but not destructors, only classes can have destructors. Can you pass parameters to destructors? No, you cannot pass parameters to destructors. Hence, you cannot overload destructors. Can you explicitly call a destructor? No, you cannot explicitly call a destructor. Destructors are invoked automatically by the garbage collector. Why is it not a good idea to use Empty destructors? When a class contains a destructor, an entry is created in the Finalize queue. When the destructor is called, the garbage collector is invoked to process the queue. If the destructor is empty, this just causes a needless loss of performance. Is it possible to force garbage collector to run? Yes, it possible

partial classes and nested types

What is a partial class. Give an example? A partial class is a class whose definition is present in 2 or more files. Each source file contains a section of the class, and all parts are combined when the application is compiled. To split a class definition, use the partial keyword as shown in the example below. Student class is split into 2 parts. The first part defines the study() method and the second part defines the Play() method. When we compile this program both the parts will be combined and compiled. Note that both the parts uses partial keyword and public access modifier. using System; namespace PartialClass {   public partial class Student   {     public void Study()     {       Console.WriteLine("I am studying");     }   }   public partial class Student   {     public void Play()     {       Console.WriteLine("I am Playing");     }   }   public class Demo   {     public static void Main()     {       Student StudentObject =

Remoting and Interfaces interview questions

What is .NET Remoting? .NET Remoting allows objects to interact with one another across application domains. What are the 2 message encoding formats supported by .NET Remoting and when do you choose one over the other? Message Encoding Formats: 1. Binary encoding. 2. XML encoding. Applications can use binary encoding where performance is critical, or XML encoding where interoperability with other remoting frameworks is essential. What are the two types of .NET remote objects? 1. Client-activated objects - Client-activated objects are under the control of a lease-based lifetime manager that ensures that the object is garbage collected when its lease expires. 2. Server-activated objects - In the case of server-activated objects, developers have a choice of selecting either a "single call" or "singleton" model. The lifetime of singletons are also controlled by lease-based lifetime. What is considered as Remote Object? Any object outside th