The difference between List<MyClass> and MyClass[] [duplicate] - c#

This question already has answers here:
Array versus List<T>: When to use which?
(16 answers)
Closed 7 years ago.
What is the difference between List<MyClass> and MyClass[] in C#.
Thanks

MyClass[] is an array, and once set in size it can't grow.
A List<MyClass>, however, can have things constantly added to it.

Related

Convert List<> to Task<List<>> [duplicate]

This question already has answers here:
Creating a task wrapper around an existing object
(3 answers)
Closed 2 years ago.
Is there a way to convert a list from List<> to Task<List<>> ? I know Task<List<>> to List<> but I don't know to other direction.
Thanks,
Have you tried Task.FromResult(list)? Where list is the variable storing reference to your Collection.
I think you want Task.FromResult(* your List<> here *)

What is a byte[][] in C#? [duplicate]

This question already has answers here:
Differences between a multidimensional array "[,]" and an array of arrays "[][]" in C#?
(12 answers)
Closed 4 years ago.
While coding a server, I came across something that I didn't recognize, which is byte[][].
What does this syntax mean, and how do I get rid of the message?
It's a Jagged Array in C#. To be short, it's an Array of Arrays holding bytes.

Check a list has set of values [duplicate]

This question already has answers here:
Determine if a sequence contains all elements of another sequence using Linq [duplicate]
(4 answers)
Closed 8 years ago.
I have two sting lists
List<string> list1=new List(){"1","2","3"};
List<string> list2=new List(){"1","2"};
What will be the easiest way to check if list1 contains the values in list2.
How about
list1.Except(list2).Any();
Try using
[listName].Except(SecondListName).Any();
This should work.

Difference between IEnumeration<T> instead and List<T>? [duplicate]

This question already has answers here:
IEnumerable vs List - What to Use? How do they work?
(11 answers)
IList vs IEnumerable for Collections on Entities
(2 answers)
Closed 9 years ago.
I am confused. Can anybody help me to understand Difference between IEnumeration<T> instead and List<T>?
You mean IEnumerable<T>. It's the base interface of all collection types like arrays or generic List<T>.
You can for example create a List<int>:
List<int> ints = new List<int>(){ 1,2,3 };
But since it implements IEnumerable<T> you could also declare it in this way:
IEnumerable<int> ints = new List<int>(){ 1,2,3 };
This has the advantage that you cannot modify ints since Remove comes from ICollection<T>.

Make list immutable [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Immutable List in C#
Is it possible to make a list immutable
You can use ReadOnlyCollection<T> instead.
List<T>.AsReadOnly() returns a readonly wrapper, so that you can't add/remove/replace elements.
To be truly immutable, the type T must be an immutable Type.

Categories