#65 Clustered Vs Non-Clustered Index

Need: Data/Records are Stored in heap,they are generally put up in the next available space over heap without any arrangement(Sorting).This kind of strategy is good when every time data is inserted,but when a selection over data is made on heap,we would encounter performance barrier and our selection query would be too slow because of our arrangement of Data over heap. Indexing provides a solution by defining an arrangement of records over heap.


1.Clustered Index :Only one Per Table and Uses B-Tree where each leaf node points to data in heap.They are sorted and B-Tree Structure Changes every time when an insertion is made.

2.Non-Clustered Index(NCI):There can be one or more NCI per Table and their leaf node does not point to data but instead point to address/Location.

#64 ViewData and ViewBag

They are responsible for passing data from controller to view.


1.It is a dictionary,which holds keys as strings.

2.It can be used to store any complex data.

3.They have to casted/Null check has to be made in view to avoid Error.


1.They use dynamic property listed with C#4.0

2.They do not require type casting of complex objects.


public ActionResult Index()
ViewData["Sample"] = "Sample ViewData";
ViewBag.Hello = "Sample ViewBag";
return View();

They are accessed in view with respective Name declared in controller