EnjoySharePoint YouTube Channel

Create generics lists in C#.Net

In this post, we will discuss how to create lists in C#.Net. Also, you can check out my previous posts:
We can create list objects by invoking the default constructor. In generic class List<T> we need to specify the type for the values of the list with the declaration.
Ex: var intList = new List<int>();
The default constructor creates an empty list. As soon as elements are added to the list, the capacity of the list is extended to allow four elements. If the fifth element is added, the list is resized to allow eight elements. If eight elements are not enough, the list is resized again to contain 16 elements. With every resizes the capacity of the list is doubled.
But you can also define the size while declaration like below:
List<int> intList = new List<int>(10);
But programmatically also you can set or get the size like below:
Set Size:
intList.Capacity = 20;
Get Size:
int size = intList.Capacity;
Also you can initialize a list like below:
var intList = new List<int>() {1, 2};
You can add elements to a list by using the Add method:
var intList = new List<int>();
Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →