Why do we need generics? What are the significances of MSIL?

Generics 

  • Generic is common to write a program that processes a collection - e.g. a collection of numbers, a collection of contacts, a collection of Names, etc. With generic programming, we can write code that handles a collection 'in the general' and C# handles the specifics for each collection type, saving you a great deal of work.
  • Generic collection in C# is defined in System.Collection.Generic namespace. It provides a generic implementation of standard structures like List, Stack, Queues, Dictionaries, etc.


E.g.


using System;  

using System.Collections.Generic;  

public class GenericList  

{  

    public static void GenericListMethod()  

    {  

        List<int> genericList = new List<int>(); 

        // No boxing, no casting:  

        genericList.Add(12);  

        genericList.Add(13);  

        genericList.Add(14);  

        genericList.Add(15);   

    } 

There are mainly two reasons to use generics as in the following:

1. Performance: Collections that store the objects use boxing and unboxing on data types. A collection can reduce the performance. By using generics it helps to improve the performance and type safety.

2. Type Safety: there is no strong type of information at compile time as to what it is stored in the collection.


Significance of  Microsoft Intermediate Language (MSIL)

  • During the compile time, the compiler converts the source code into Microsoft Intermediate Language (MSIL). Microsoft Intermediate Language (MSIL) is a CPU-independent set of instructions that can be efficiently converted to the native code. During the runtime, the Common Language Runtime (CLR)'s Just In Time (JIT) compiler converts the Microsoft Intermediate Language (MSIL) code into native code to the Operating System.
  • When a compiler produces Microsoft Intermediate Language (MSIL), it also produces Metadata. The Microsoft Intermediate Language (MSIL) and Metadata are contained in a portable executable (PE) file. Microsoft Intermediate Language (MSIL) includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations.

Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Explain Parallel Efficiency of MapReduce.

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?