What is C#?
With .NET Framework 2.0 Microsoft included another element named Generics. Generics influenced re-usability to highlight of protest introduction more grounded by enabling programmers to make different programming components like classes, interfaces, delegates, capacities and so on which manages the diverse sort of information without bargaining the sort security. It implies that programmers can make write safe capacities with adaptable information compose.
In .NET we have numerous inbuilt gathering classes accessible in System. Collection namespace. While working with these accumulation classes we confront some execution related issues.
- These classes work with the ‘question’ information compose because of which these classes treat each esteem put away inside it as an Object.
- That when whole number esteem is put away in it is verifiably changed over into a question write. This Process is called as Boxing.
- While recovering information from the gathering, information is recovered as protest compose which should be type thrown to the particular sort. This procedure is called as unboxing.
Each time when you include or expel information from these accumulation boxing and unpacking is performed which prompts execution corruption and because of utilization of ‘protest’ information compose the accumulations are not type safe. To conquer these issues we need to have an instrument which is type safe and disposes of the requirement for boxing and unpacking and it is only ‘Generics’.
Suppose you want to create a Stack class for different data types. There are two ways you may perform this task:
- Make diverse classes to execute stack which works for various information composes.
- The other route is to make a stack class with ‘object’ as parameter. This approach is superior to anything the main approach yet has restrictions.
- It debases the execution in light of the fact that each time while embeddings information the qualities are boxed and keeping in mind that recovering information should be unpacked.
- You have to make a class which acknowledges an information compose as parameter in the precise brackets<>.Data writes are determined at the season of making object as delineated in the code given underneath.
Stack class is made with the Generic kind T where T is a placeholder it is supplanted with the real information write when we make question of stack class
Advantages of Generic:
- Type safety
- Improved performance
- Better code re-usability
If you are looking for one of the best Computer training institutes in Pune then NIIT Pune is a place where all your searches end. NIIT Pune offers various computer and Banking courses, all under one roof. They have few of the best Teachers from the industry to teach the courses to their students.
Visit us at: NIIT Pune