Reputation: 2237
I'm creating task with array. See below please:
Task<int>[] tasks = new Task<int>[]
{
clientT1.UpdateCatalogBulkArticlePrices(catalogCode, data.prices),
clientT1.UpdateCatalogArticleSizesBulk(catalogCode, data.sizes)
};
My question is how to add new task in my tasks
object.
Something like that:
tasks.add(...);
Upvotes: 1
Views: 355
Reputation: 681
Arrays have a fixed sized in construction a better solution would be using a list, but if you need to return an array, and you would like to use the method add, you could try something like this.
var t = new List<Task<int>>();
t.Add(clientT1.UpdateCatalogBulkArticlePrices(catalogCode, data.prices));
t.Add(clientT1.UpdateCatalogArticleSizesBulk(catalogCode, data.sizes));
Task<int>[] tasks = t.ToArray();
Upvotes: 1
Reputation: 511
You may need to create a List of Tasks :
var tasks = new List<Task<int>>();
And then:
tasks.Add(AnotherTask);
Upvotes: 1
Reputation: 4936
List<Task<int>> tasks = new List<Task<int>>
{
clientT1.UpdateCatalogBulkArticlePrices(catalogCode, data.prices),
clientT1.UpdateCatalogArticleSizesBulk(catalogCode, data.sizes)
};
tasks.Add(...)
Upvotes: 2
Reputation: 14701
You are using Array construct in C#. By definition, size of an array is fixed in construction. You can not add new elements to it. You need to use something like ArrayList/List for this purpose.
List<Task<int>> tasks = new List<Task<int>>();
tasks.Add(clientT1.UpdateCatalogBulkArticlePrices(catalogCode, data.prices);
tasks.Add(clientT1.UpdateCatalogArticleSizesBulk(catalogCode, data.sizes))
later.
tasks.Add(anotherTask);
Upvotes: 2