This may seem an easy question, but not to me, also a search has led to nothing. Up until now the only .net programming I have done is with Delphi Prism. With Prism I can do things like:
var l := new List<String>(['A','B','C']);
or
var l := new List<String>;
l.AddRange(['A','B','C'];
but can I do a similar thing in C#, or do I have to do it like:
var a = new String[] {"A","B","C"};
var l = new List<String>(a);
An array of strings is created and passed to the constructor, populating the list with the elements of the array. The AddRange method is called, with the list as its argument. The result is that the current elements of the list are added to the end of the list, duplicating all the elements.
List<T>. AddRange(IEnumerable<T>) Method is used to add the elements of the specified collection to the end of the List<T>.
AddRange is used to add multiple elements. The add method inserts the item at the end of a collection. AddRange method is used to insert a set of records into a collection. The addRange method is also used to add an array of nodes that are previously created in the collection.
var l=new List<String>() {"A","B","C"};
this will work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With