我有一个循环,生成约150个唯一的字符串。如何将这些字符串添加到数组?

这是我的循环:

for (int intCounter = 0; intCounter < projectCount; intCounter ++)
{
    var projectname = project.value[intCounter].name;
    var releaseUri = "http://tfs1:8080/tfs/defaultcollection/" + projectname + "/_apis/release/releases?api-version=3.0-preview.2&searchText=911&minCreatedTime=" + date + "T00:00:00.00Z";
    Console.WriteLine(releaseUri);
}


Console.WriteLine(releaseUri)打印每个URL。但我想将releaseUri存储在数组中。

最佳答案

@ShaneP,

您将需要像这样在for循环之外声明一个数组。

string[] releaseUriArray = new string[projectCount];

for (int intCounter = 0; intCounter < projectCount; intCounter ++)
{
    var projectname = project.value[intCounter].name;
    var releaseUri = "http://tfs1:8080/tfs/defaultcollection/" + projectname + "/_apis/release/releases?api-version=3.0-preview.2&searchText=911&minCreatedTime=" + date + "T00:00:00.00Z";
    // Here you are adding the releaseUri strings to the releaseUriArray
    releaseUriArray[intCounter] = releaseUri;

}

// print your uris from the array here
for (int intCounter = 0; intCounter < projectCount; intCounter ++)
{
    var releaseUri = releaseUriArray[intCounter];
    Console.WriteLine(releaseUri);
}

10-02 01:41