C# Collections in four minutes - Collections & Collection Interfaces


This article aims to give you an overview of collections that are available in C#.

What is a Collection?

A collection normally means a type whose purpose is to manage a group of other objects in memory and to provide access to those objects. Collection classes are specialized classes for data storage and retrieval. Collections typically include methods to add, remove, count and for, foreach for iterate through objects.
ref - https://docs.microsoft.com/en-us/dotnet/api/system.collections?view=netcore-3.1

Various Collections of C#

There are two types of collections Arrays and Advanced Collections. Advanced Collections can be divided into two. Generic & Non-Generic collections.

➤ Non-Generic Collections

The data type of the collection is not pre-defined.
These collections are the various commonly used classes of the System.Collection namespace.
  • ArrayList
  • SortedList
  • Stack
  • Queue
  • Hashtable
  • BitArray
I hope not to explain these data types further because these are more familiar if you are doing any programming language.

➤ Generic Collections

The data type of the collection is pre-defined.
These collections are the various commonly used classes of the System.Collection.Generic namespace.
Note:
  • These collections(below) can be Generic or Non-Generic.
  • is the type of the object.
  • TKey TValue are Key and Value pairs for objects.
  • Explore the methods and properties of each collection to complete your knowledge.

➧ BitArray

  • A bit array is a collection of bits
  • Bit arrays compactly store bits. 
  • Most commonly, they are used to represent a simple group of boolean flags or an ordered sequence of boolean values.

➧ List<T>

➧ Dictionary<TKey, TValue>

  • dictionary is a collection of unique key/value pairs where a key is used to access the corresponding value. 
  • Dictionaries are used in database indexing, cache implementations, and so on.

➧ SortedList<TKey, TValue>

➧ Stack<T>

  • stack is a Last In, First Out (LIFO) collection of elements where the last element that goes into the stack will be the first element that comes out.

➧ Queue<T>

  • queue is a First In, First Out (FIFO) collection of elements where the first element that goes into a queue is also the first element that comes out.

➧ Hashset<T>

  • hash set is a set of unique values where duplicates are not allowed.


⇢➤Further Reading

➤ Collection Interfaces

  • An interface is a completely abstract class, which contains only abstract members.
  • It is declared using the interface keyword.
  • The interface simply describes what a class should do. The class implementing the interface must define how to accomplish the behaviors(inverse of inheritance).
These Collection Interfaces helps to transfer data from a thread to another thread without any problem. 

Note:

Normal collections are not compatible to do such work. 
Ex:- When we build a multi-thread application the UI is running in thread A. So we assign another work like sorting a list to thread B. Then the sorted list should be displayed in the UI thread(A). So a List is unable to pass between thread perfectly because objects of the list are given from memory address. But when we use IList or any other IEnumarerable Collection Interface, it creates copy a copy and pass it to the UI thread without any problem.


Some of the Collection Interfaces are in the following section.
➧ IEnumerable

➧ ICollection

➧ IList

➧ IDictionary


The following diagram is for the relation between the interfaces.

Different interfaces provide different functionalities. The thing is developers should know about what to use and when to use them to achieve different functionalities.



Summary

I hope you will enjoy the generic, non-generic collections and collections interfaces in C#. 

Your valuable feedback, question, or comments about this article are always welcome.

Comments

  1. Buy covid-19 vaccination card online +1(901)878-9747
    We produce a verified registered cdc covid19 vaccination cards that can enable you travel or present at your job side
    buy registered covid19 vaccination cards at affordable prices


    Buy Covid-19 Vaccine Certificate Online

    Buy CDC Vaccination cards online

    Do you want to travel abroad an you need a Covid-19 Vaccine Certificate without taking the vaccine?
    We are here to help you obtain a valid Covid-19 Vaccine Certificate without taking the vaccine.
    Some people do not have time to take the vaccine,
    others do not have access to the vaccine.
    To travel abroad you need to provide a valid Covid-19 Vaccine Certificate to prove you have taken the vaccine.

    Buy Fake US Dollars Online
    Buy Undetectable Counterfeit Money

    Buy high-quality undetectable grade AA+ counterfeit banknotes & Registered Documents Online
    We are the best and Unique producer of Super Undetectable Counterfeit Banknotes 210 million of our products circulating around the world. We offer only original high-quality counterfeit currency NOTES and Documents . We ship worldwide. We also print and sell Grade A banknotes of over 150 currencies in the world. Here is your chance to be a millionaire. Our money is perfectly reproduced, Indistinguishable to the eye and to the touch. We are sending in various sizes, packed and hidden. All our notes carry all the holograms and water marks and passes the light detector test. We will deliver the money directly to your home without the interference of customs. We have a Huge quantity ready in stock. EUROS, DOLLARS AND POUNDS. We are Professionals in counterfeiting and we produce SUPER UNDETECTED COUNTERFEIT MONEY for all currencies. Our notes are industrially and professional produced.
    The security features included on the bills:

    -Passes pen trace test!
    -Microprint!
    -Red and Blue fibers!
    -60% cotton 40% linen, same as real currency!
    -High Quality Print!
    -Correct colors!
    -Correct Seals!
    -Correct serial number font!
    -Holograms and Holographic Strips!
    -Micro-Lettering!
    -Metallic Ink and Thread!
    -Watermarks!
    -IR Detection!
    -Ultra-violet features!
    -See through Features!
    -Different serial numbers!
    These features make our bills to be 100% undetectable, 100% safe and secure to use in any of these areas: BANKS, CASINO, ATM, MONEY CHANGERS, STORES. They are 100% Undetected.
    CALL/TEXT : +1 (901) 878-9747

    WHATSAPP: +1 (901) 878-9747

    website link : https://approvedocs.com/no-vaccine-no-problem/

    Telegram: @Approveddocumente

    Customer Support: infor@approvedocs.com

    ReplyDelete

Post a Comment

Popular posts from this blog

MS SQL Server with AWS RDS - Connect your local Relational Database to Cloud

Fictional Hackers who inspires you - (MARVEL Vs. DC)

An Overview of Sri Lanka's Multilingual Heritage