Posted in .Net Basics

Generics in C# .Net

When we look at the term “Generic”, unrelated to our programming world, it simply means that it is not tied to some predefined type and in programming terminology:

Generics allow you to define type-safe classes without compromising type safety, performance, or productivity.

In our programming world, “Generic” provides the functionality to handle any Type in generic and Type safe manner. That means we can have a single array class that we can use to store a list of Employee or a list of Items, and at the time of using them, we’ll be able access them in the collection directly as a list of Employee or Items, and not as Object. That means we don’t need to do boxing/unboxing or casting, which in turn gives us a performance boost.

Continue reading “Generics in C# .Net”

Advertisements
Posted in .Net Basics

Release Managed & Unmanaged Resources

The basic difference between a managed and unmanaged resource is that the garbage collector knows about all managed resources, at some point in time the GC will come along and clean up all the memory and resources associated with a managed object. The GC does not know about unmanaged resources, such as files, stream and handles, so if you do not clean them up explicitly in your code then you will end up with memory leaks and locked resources.

Continue reading “Release Managed & Unmanaged Resources”