 Hello everyone. I am Professor Zatathri Gangmal from Walchin Institute of Technology, Solapur. So in this video we are going to see overview of collections in C-Sharp. This is an important topic. Many students don't understand working with collections. But we will make it very simple by this video. Learning outcomes at the end, students will be able to describe the advantages of collections, differentiate various collection types. These are the two outcomes of this particular video. Describe the advantages of collection and differentiate various collection types. So now, need of collection. Starting with need of collection, why we are going to learn collections? Why collections came into existence? Since there are some limitations with arrays. Everyone is aware with using array, right? What array is? Array is nothing but collection of similar data type data which is stored in a sequential manner, right? So now, there are some drawbacks with the collection. For example, size of array is fixed, you have to define it well before, right? We cannot change the size of array run time. Second thing is that it is collection of same data type. If I want to store one of integer, another of string and in a same array is not possible. I need to stick to the basics like it should be of same data type. Third, arrays does not impose any mechanism that inserting and retrieving using the element. Now, if you are going to retrieve or insert at a particular position, arrays I will work sequentially. The time required to insert is done, but it is more, right? So now, this is a simple example of arrays, how we declare array and how we store values into an array. Ind array equal to new array. Here we created dynamically, so that this is object, array is an object here, ok? Now if I want to store 10, 12, 15 and any other value into my array, it will be start from the zeroth index. So, this is zeroth index, then first index and second index and the values are stored appropriately. Here, arrays works as an object, therefore we have a reference type stored to that particular array. Now, so there are some basically three drawbacks with arrays, one is that it is, size is fixed. Second is that we cannot change the data type, multiple data, we cannot have multiple data types, only one data type is allowed. Third, inserting and retrieving at a particular position is difficult in array. So, these are the three disadvantages with arrays, simple arrays, ok? So, to overcome these challenges and limitations in array, collections are introduced. Now, one more example of arrays, if I want to store string, name equal to new string, if I want to store such in Raoul, Saurav, Lakshman, so likewise zeroth index, first index, second index and third index, ok? If I want to display all these elements using for each loop, for each loop is one more way, it is similar to for loop, here only it will run iteratively, int i in name. So, i will work as a iterator, so console.write line i, the value will be printed. So, likewise output will be such in Raoul, Saurav, Lakshman, ok? So, this is how simple arrays work, but here if suppose I want to store 10, 10 will not be stored as an integer, it will be stored as a string, so only strings are a lot, because arrays are of same data type, ok? Now, collections, coming back to collections, collections overcome the limitations of array, collection size can be increased dynamically. So, the drawbacks of arrays are overcome in collection, you can increase the size at runtime, if suppose I have declared the size of collection as 10, and at runtime I want the size to grow, if I want to say I want to grow it to 50, so that is possible with collections, you can add any number of elements in collection. And another drawback of array, you cannot insert and retrieve, it is difficult, whereas here element can be inserted and retrieved from specific location with ease, that is the biggest difference using arrays and using collections. And different type of objects are also allowed in collections, so all the limitations of arrays are overcome in collection. Now, what are different classes in collections? So, collection is nothing but a superficial thing in which we have various classes, so correction is a namespace in which we have various classes, like for example, array list is there, stack, queue, hash table, sorted list, but not limited to this, these are some important collection classes, which we will be studying in the coming videos. What are different collection classes? Array list, stack, queue, hash table and sorted list, now what array list is, what array list collection, why we have so many types? Collections not only retrieve and store data, but it also is used for various purposes as per the need. Let us say I want to store database of the complete city, a metro city, if let us say there are 20 lakhs of people in that particular city, if I want to store the data of all those 20 lakh people in my database, which collection type should be used? It depends. So, if I want to store only phone numbers, a different collection will be used. If I want to store names, different collection will be used. If I want to store addresses, different collection will be used. So, likewise, collection will be depending on the application, it is an application oriented thing, okay? And one more thing, it also depends on, let us say, what you want later. If our retrieval is more, different collection will be used. If insertion is more, there is no very few retrieval thing, different collection will be used. So, likewise, it depends. Therefore, we have so many collection types, okay? So, now, first coming to array list. What array list is going to do is array, but can grow dynamically, it is similar to an array. It can grow dynamically. And the stack works on the principle of last in first-out manner. Queue works on the principle of first-in-first-out manner. So if your application demands that the data, how it is inserted, should be retrieved in the same way, I will prefer queue collection. If application demands, like data should be stored in a leaf of fashion, I will use queue. Stack. So, Asstable. Asstable works on the principle of key value pair. A unique key will be inserted for every key, there is a particular value. Let's say, a phone number. For every phone number, there is a particular name associated. So key will be unique, okay? Value can be repeated. Sorted list. What sorted list is going to do? It's an extension of Asstable here. Same key value pair principle is used and the result is sorted. Always the data is stored in a sorted manner. So if an application demands my, everything should be sorted, let's say for telephone dictionary, everything will be sorted according to the surname. So in that case, sorted list is preferred. It's a small question for you, which collection class is similar to array? You can take a pause here and try to answer this question. Okay? Now, the answer for this question is array list. Just now we have seen, array list is an extension of array, which only difference is that array list grows dynamically. Next is iCollectionInterface. In iCollectionInterface, contains three properties and one method. So three properties are there. In C-sharp, we have properties and methods and data types. So in property, we have count property, returns the number of elements in the collection. So this count property helps us to find how many elements are present in my collection. Second is synchronized. Property returns a Boolean value. So whether it is synchronized or not, when we require synchronized, in case of threading. In case of threading, I need to find whether it is synchronized or not. Third is Syncrude. Property returns an object. So it basically returns an object instead of a Boolean value. And one more method we have that is copy to method. Copy is the element to array from the starting index. So everything if I want to copy from one collection to another collection, that is possible using copy to. We can just incorporate this method. So all these are already contained in iCollectionInterface. Now first collection type is ArrayList. It's a general overview of about ArrayList. System.collection.arrayList is the namespace for ArrayList and any other. So system.collection is the root namespace. Inside it, we have ArrayList, tag, queue, etc. Now size of ArrayList, as I said, it is dynamically. It will grow dynamically. Though you define it, you can later change it. This is a simple program elaborating ArrayList. ObjectArrayList is declared new ArrayList. Here size is not specified. You can even specify the size. Second, you can add one by one element. List.add this particular method adds element into your ArrayList. 10, 20, let's say 10 is inserted, 12 is inserted, 23 is inserted. So for each look, in tie in array, console.writeLine will display all the elements in this particular ArrayList. So these are some of the references which I have referred. C programming, quickly learn C programming by Hamilton and e-resources programmers heaven. So coming back, all details can be found in that particular references. Similarly, here instead of add, you can go with stack also. Stack also adds, but it will do on the principle of LIFO, last in first-out. And queue will work on the first-in-first-out principle. So variation is there, but at the end, data is going to get stored. And it again, I repeat that it is purely based on application. What application you are going to use based on that, we have to choose the particular collection. So in further videos, we will be seeing more collection types. That's it from this video.