Monday, January 21, 2013

Interview Questions

Qs (03-Apr-14)
Q. Implement a PhoneBook Application with ability to search numbers by name. A same name can represent different persons.
Ans. - It can be easily implemented with any of the List or Dictionary collections with a Linq query to search out the records.
But check the Lookup class, which will be most appropriate for this scenario.

Q. How can I implement my own garbage collection algo? How can I ensure a object created by the application is no more used?
Ans: Mark and Sweep or Maintain Reference Table. Traverse to see if the object is 'Reachable' thought the reference tree from leaf to root or root to leaf.

Q. What are weak references? How can you implement it.
Ans:

Q. How to communicate between two UI threads?
Supplementary : One UI grid is binded to Market data, the other UI Grid having Orders is binded to another service. On selecting record from Mkt data grid, It would be able to select the related record on the Order Grid.
Ans:


C#

Q. What is managed code and managed data?
Ans:
Q. What is CTS?
Ans:
Q. What is MSIL?
Ans:
Q. What is Garbage Collector? How it works?
Ans:
Q. Describe How GC works in the forms of generations?
Ans:
Q. What is the significance of CLR?
Ans:
Q. What is an assembly? What is dynamic assembly loading?
Ans:
Q. What is code access security?
Ans:
Q.  In a .net class can I override GetType() method? If not why?
Ans:
Q. What is the base class of any .net class? What are the default methods of a .net class?
Ans:
Q. What is the difference between CCW and RCW?
Ans:
Q. What are private assemblies and shared assemblies? How to build shared assemblies?
Ans:
Q. What is Test Driven Development? How to do TDD in .net?
Ans:
Q. what are covariance and contravariance?
Ans (Ref: Herbert Schildt/McGraw Hill): Covariance enables a method to be assigned to a delegate when the method’s return type is a class derived from the class specified by the return type of the delegate. Contravariance enables a method to be assigned to a delegate when a method’s parameter type is a base class of the class specified by the delegate’s declaration.
e.g.
using System;
class X {
  public int Val;
}
// Y is derived from X.
class Y : X { }
// This delegate returns X and takes a Y argument.
delegate X ChangeIt(Y obj);
class CoContraVariance {
  // This method returns X and has an X parameter.
  static X IncrA(X obj) {
     X temp = new X();
     temp.Val = obj.Val + 1;
     return temp;
  }
  // This method returns Y and has a Y parameter.
  static Y IncrB(Y obj) {
     Y temp = new Y();
     temp.Val = obj.Val + 1;
     return temp;
  }

  static void Main() {
    Y Yob = new Y();
    // In this case, the parameter to IncrA
    // is X and the parameter to ChangeIt is Y.
    // Because of contravariance, the following
    // line is OK.
    ChangeIt change = IncrA;

    X Xob = change(Yob);
    Console.WriteLine("Xob: " + Xob.Val);

    // In the next case, the return type of
    // IncrB is Y and the return type of
    // ChangeIt is X. Because of covariance,
    // the following line is OK.
    change = IncrB;
    Yob = (Y) change(Yob);
     Console.WriteLine("Yob: " + Yob.Val);
  }
}
Q. what is   ref  by ref?
Ans:
Q.Write a LINQ query and What is the use of it?
Ans:
Q.Justify struct is allocated in heap if not where is it allocated?
For e.g.
          struct a …
          a a1 = new a( 10 );
          Where is a1?
Ans: a1 is allocated in stack, new a (10) is an indication to compiler to call the specific constructor.
Q. When to use extern keyword?
Ans: PInvoke, DllImport, the extern modifier means that the method is implemented outside the C# code.
Q. What is an event? Can events be declared other than a property of a class? How?
Ans:
Q. What are the difference between and abstract class and an Interface?
Ans:
Q. What is shadowing?
Ans:Hiding base class method by using new override
Q. What is the boxing and unboxing?
Ans:
Q. Can struct implement an interface? If so give and e.g.
Ans:
Q. What is a delegate? How delegates are thread-safe?
Ans:
Q. What is the difference between const and readonly?
Ans:
Q. What is the significance of foreach keyword?
Ans: foreach internally uses GetEnumerator of the container.
Q. Suppose within a try finally block an exception occurs, will finally block gets executed?
Ans:
Q. What is the use of static class? (note: not a static variable of a class)
Ans:
Q. What is the use of “is” and “as” keywords?
Ans:
Q. What is the difference between “ref” and “out” keywords?
Ans:
Q.The “sizeof” operator can only be used in the unsafe mode. Is it true or false?
Ans:
Q. What does using “statement” does?
Ans: Defines a scope at the end of which an object will be disposed by calling Dispose method.
Q. I have two interfaces say iterface1 and interface2 both has a method whose signature is same.
I need to implement both the interfaces in a class class1. Is it possible? Is it a compilation error?
Ans:
Q. What is yield return ?
Ans:
Q. What is a partial method? Is it possible to define
public partial int f()
{
return 0;
} in a partial class?

Ans:
Q. What is the significance of StringBuilder?
Ans:
Q. How to use pointer types in C#? What is the significance of unsafe keyword?
Ans:
Q.  Is it possible to use goto case with in a switch block? If possible give us a usecase?
Ans:
Q. I have a sealed class say it is string, how to introduce a new method into string class?
Ans:
Q. In a 64 bit number I want to know the 60th bit is set or not? Is it possible in C#? How to ?
Ans: possible, i64bitno & (1<<60 span="span">
Q. What is polymorphism? Discuss with e.g.
Ans:
Q. What is the difference between composition and aggregation?
Ans:
Q.  What is “is-a” relationship among classes?
Ans. : Inheritance, discuss in detail.
Q. What is overloading? Which operator cannot be overloaded in c-sharp?
Ans:
Q. What is cloning? What is the difference between IClonable and a copy constructor?
Ans:
Q. What is an iterator?
Ans:
Q. What is the access modifier for explicitly implemented interface method?
Ans: In principle we cannot change the access modifier, by default it is marked internal.
Q. What is the significance of typeof operator?
Ans:
Q. How to define a sealed method in an abstract class?
Ans: : We cannot define a sealed method in an abstract class as long as it is a base class. However in a derived abstract class, we can seal an abstract override method where the implementation is final and no more override possible.


Multithreading


Q.Will it be possible to get return value from the thread delegate method, if not why?
Ans:
Q.  How can I pass paramters to a thread delegate method?
Ans:
Q.what are thread synchronization context and execution context? What is context switching?  What actually happens when we say context switch incurs overhead?
Ans:
Q. From Cross process point of view, except the execution scope, what else difference is there between Mutex and Monitor? How Mutex internally works?
Ans:
Q. How memory is allocated internally when a thread is created?
Ans:
Q. what is difference between Autoresetevent and Manualresetevent? When to call .WaitOne() /.Set() method?
Ans:
Q. what is   IAsync ?
Ans:
Q. What is the use of lock keyword? And do we need to lock a private variable of a class?
Ans:
Q. Questions related to Autoresetevent?
Ans:
Q. What is the use of lock keyword? Is it possible to use a value type as a lock variable?
Ans:
Q. What is a thread?
Ans:
Q. What is an application domain?
Ans:
Q. How do in-process and cross-process communication work in CLR?
Ans:
Q. Why does my code get a security exception when I run it from a network shared drive?
Ans:
Q. Can I use Win32 API from .Net program? How?
Ans:


WCF

Q. When to use/not to use tcpbinding, httpbinding, msmqbinding ?
Ans:
Q. What is FaultException  (in WCF)?
Ans:
Q. What is EndPoint, Service contract?
Ans:
Q. Is it possible to run more than on Service contract on an EndPoint?
Ans:
Q.What is a WebService? Explain the role of XML in WSDL and related XSD.
Ans:
Q. What is a socket? What are protocols supported in .Net framework while programing sockets?
Ans:
Q. What is remoting in .net? What is the difference between singleton and single call?
Ans:
Q. What is WCF? Brief what is address, contract, binding (endpoint) and transport in WCF?
Ans:
Q. How to overload operations in WCF?
Ans:
Q. What is serialization in .net framework? Why do we need serialization? What are different kinds of serialization techniques available in .net framework? Have you done custom serialization? If so what is the use case?
Ans:


DesignPattern

Q. What is the difference between AbstractFactory and Factory method, with practical example if possible?
Ans:
Q. How does  Façade work?
Ans:
Q.  What is Dependency injection? What is the use and how it is related to Nunit testing?
Ans:
Q. Static class and Singleton pattern?
Ans:
Q. Have you used design patterns in development? If so what, why? Discuss about design patterns applied in .net framework.
Ans:
Q. What is dependency injection? How to achieve this in c-sharp?
Ans:


Database

Q. What is an Index? (DB) and different types of it?
Ans:
Q. Can Index improve the performance of the query?
Ans:
Q. What columns should be indexed?
Ans:
Q. How a query can be optimized in general terms (i.e. not given any query) ?
Ans:
Q. How to find where is the issue in query with any tool?
Ans:
Q. Write a query to find 3rd highest salary in an employee table (Any other way to write the same)?
Ans:
Q. Write a query that will join three tables?
Ans:
Q.What is LEFT OUTER JOIN and give a scenario where this will be useful?
Ans:
Q. What is temporary table and give a scenario where this will be useful?
Ans:
Q. Dynamic SQL how to write and what are the disadvantages
Ans:
Q:Write a query to find the duplicate values in a row along with number of occurrence of the value?
Ans:


No comments: