gpt4 book ai didi

c# - 如何在C#中将项目添加到数组

转载 作者:太空宇宙 更新时间:2023-11-03 17:48:05 26 4
gpt4 key购买 nike

我有一个循环,生成约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);
}

关于c# - 如何在C#中将项目添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54542415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com