Wednesday, September 12, 2012

ASP.NET MVC FAQ


1. Can you have viewstate in ASP.NET MVC?

  • Ans: No

2. Can you do unit testing of view in ASP.NET MVC?

  • Ans: Yes

3. Is routing happens every time a page request or only first time?

  • Ans: - Only first time
  • - Shared Sub RegisterRoutes(ByVal routes As RouteCollection)



http://jinaldesai.net/asp-net-mvc-3-interview-questions/

Tuesday, September 11, 2012

Datastructures in .NET


a.       Stack:
·   FILO (first in last out)
·   Push(object o) – insert an object at top of stack
·   POP() – removes object at top of stack
·   Peek() – returns object at top of stack without removing
·   One of the classic examples of stack in .net framework is in memory management of value types.
·   There are non generic collection stack object (System.Collections.Stack) and generic collection stack object (System.Collections.Generic.Stack)



b.      Queue:
·   FIFO
·   Enqueue(object o) – add an object at end of queue
·   Dequeue() – remove object at beginning of queue
·   Peek() - return object at beginning of queue
·   First object entering to the Queue, exits first
·   One of the classic example of queue implementation in MSMQ
·   Queue is used in the highly reliable communication scenarios. Even if the message channel not available, messages are stored in the queue and transmitted once the channel is up.
·   There are non generic collection object (System.Collections.Queue) and generic collection object (System.Collections.Generic. Queue)


c.       Hashtable           
·   Hashtable stores key – value pair
·   Is organized based on the hash code of the key
·   Each element in hashtable is stored as DictionaryEntry object
·   A key cannot be null, but value can be
·   It is a non generic collection System.Collections type
·   Hashtable stores types of object
·   There is a type conversion required every time when we use hashtable

IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback, ICloneable

d.      Dictionary
·   Dictionary is similar to Hashtable (key-value pair storage)
·   It is a generic collection (System.Collections.Generics)
·   Type of the object to store in the dictionary should specify at compile time
·   Performance wise,  Dictionary is better option that Hashtable
IDictionary, ICollection<KeyValuePair>, IEnumerable<KeyValuePair>, IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback

e.      List
·   It is generics collection (System.Collections. Generics)
·   It represents strongly typed list of objects
·   Consider a scenario to store all the employee names of Satyam, then use List
·   No type conversion required hence preferred over ArrayList

IList, ICollection, IEnumerable, IList, ICollection, IEnumerable

f.        ArrayList
·   ArrayList is a non generic collection (System.Collections)
·   Size can be dynamically increase
·   ArrayList stores objects
·   Type conversion required every time when use AL
·  This affects the performance

Dependency Injection in .NET

Three Ways to Implement Dependency Injection in .NET Applications

http://www.devx.com/dotnet/Article/34066

Monday, September 10, 2012

Struct in C#.NET

            //NOTES: STRUCT

            // - struct is a value type 
            // - no need to use new keyword
            // - cannot inherit from struct(error: cannot derive from sealed type)
            // - struct allows properties/method which uses reference type.



namespace StructSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Point p;
            p.x = 10;
            p.y = 20;

            p.name = "wgi";

            Console.WriteLine(p.Add());

            Console.Read();
        }
    }


    struct Point
    {
        public int x, y;

        public string name;

        public int Add() { return x + y; }
    }


    //class newPoint : Point
    //{
    //}
}

E-Book Gallery for Microsoft Technologies

Monday, April 16, 2012

Advantage of abstract class over interface

Advantage of abstract class over interface:

Consider versioning:

·         You cannot add members to interface without breaking the existing code.  
·         But you can safely add new members to abstract classes.



Choosing between interface & abstract class:

·         Use interface when you want to implement multiple inheritance.
·         Use interface for decoupling
·         Use abstract class in case of frequent versioning scenario.

Compare 2 generic list

How to Compare 2 generic lists:

            List<int> list1 = new List<int> { 1, 2, 3, 5, 6 };
            List<int> list2= new List<int> { 1, 2, 3 };


Answer: if you are trying to see if 2 sets are equal, then the best approach is to check the except extension method on Enumerable class. And make sure that the result does not have any entries.


            var except = Enumerable.Except(list1, list2);

            if (except.Count() > 0)
                Console.Write("Not equal");
            else
                Console.Write("equal");;

Reference: