Posts

Showing posts from February, 2015

Difference between array, arraylist, List, Hashtable, Dictionary and SortedList in c#

Basic difference is that arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow. While arrays would be more performance that a list, a list would be far more flexible since you don't need to know the required size initially. Array - represents an old-school memory array - kind of like a alias for a normal type[] array. Can enumerate. Can't grow automatically. I would assume very fast insertion, retrieve and speed. ArrayList - automatically growing array. Adds more overhead. Can enum., probably slower than a normal array but still pretty fast. These are used a lot in .NET List - one of my favorites - can be used with generics, so you can have a strongly typed array, e.g. List . Other than that, acts very much like ArrayList. Hashtable - plain old hashtable. O(1) to O(n) worst case. Can enumerate the value and keys properties, and do key/val pairs. Dictionary - same as above only strongly typed via generics, such a...

Benefits and Limitation of using Cookies?

Following are benefits of using cookies for state management :- No server resources are required as they are stored in client. They are light weight and simple to use Following are limitation of using cookies :- Most browsers place a 4096-byte limit on the size of a cookie,although support for 8192-byte cookies is becoming more common in the new browser and client-device versions available today. Some users disable their browser or client device’s ability to receive cookies, thereby limiting the use of cookies. Cookies can be tampered and thus creating a security hole. Cookies can expire thus leading to inconsistency. Below is sample code of implementing cookies :- Request.Cookies.Add(New HttpCookie(“name”, “user1”))  

Difference between dataset and datareader in c#

Following are some major differences between Dataset and Datareader DataReader provides forward-only and read-only access to data , while the DataSet object can hold more than one table (in other words more than one rowset) from the same data source as well as the relationships between them. Dataset is a disconnected architecture while datareader is connected architecture. Dataset can persists contents while datareader can not persist contents , they are forward only.

MVC Interview Question with Answer Part 2

What is difference between TempData and ViewData ? “TempData” maintains data for the complete request while “ViewData” maintains data only from Controller to the view. Does “TempData” preserve data in the next request also? “TempData” is available through out for the current request and in the subsequent request it’s available depending on whether “TempData” is read or not. So if “TempData” is once read it will not be available in the subsequent request. What is the use of Keep and Peek in “TempData”? Once “TempData” is read in the current request it’s not available in the subsequent request. If we want “TempData” to be read and also available in the subsequent request then after reading we need to call “Keep” method as shown in the code below. @TempData[“MyData”]; TempData.Keep(“MyData”); The more shortcut way of achieving the same is by using “Peek”. This function helps to read as well advices MVC to maintain “TempData” for the subsequent request. string str = TempData.Peek("Td...

ASP.NET MVC Interview Question with answer Part 1

Image
What is MVC (Model View Controller)? MVC is an architectural pattern which separates the representation and user interaction. It’s divided into three broader sections, Model, View, and Controller. Below is how each one of them handles the task. The View is responsible for the look and feel. Model represents the real world object and provides data to the View. The Controller is responsible for taking the end user request and loading the appropriate Model and View. Figure: MVC (Model view controller) Explain MVC application life cycle? There are six broader events which occur in MVC application life cycle below diagrams summarize it. Any web application has two main execution steps first understanding the request and depending on the type of the request sending out appropriate response. MVC application life cycle is not different it has two main phases first creating the request object and second sending our response to the browser. Creating the request object: - The request objec...