Initializing list and collection in c#.net

Sure, here's a brief overview of initializing a list and collection in C#:

Initializing a List:
A list is a collection that can be modified. Here's how you can initialize a list in C#:

List<string> names = new List<string>(); // create an empty list
names.Add("John"); // add items to the list
names.Add("Mary");



Initializing a Collection:
A collection is a grouping of objects of the same type. Here's how you can initialize a collection in C#:

Collection<string> names = new Collection<string>(); // create an empty collection
names.Add("John"); // add items to the collection
names.Add("Mary");



Note that both lists and collections can be of different types, depending on what you need them for.

 Also, there are other ways to initialize lists and collections in C#, but these are the most basic methods.

Comments

Popular posts from this blog

How to use lamda expression for updating using LINQ

using session for login and logout in asp.net

How to post data in MVC using form collection for Beginners.