【发布时间】:2023-03-16 23:12:01
【问题描述】:
好的,所以我有这个包含 3 个项目的 Hashset,我想在其上应用一些逻辑,以便我能够为散列集中存在的每个项目附加一些预定义的 3 个值
例如,
HashSet<string> hs = new HashSet<string>(); //it could be string or some other class object
hs.add("Red");
hs.add("Yellow");
hs.add("Blue");
//Some predefined values for those strings that I want to append to them
string[] str = {Alpha, Beta, Gamma}
我想要的输出是:
unique strings associating "RedAlpha", "YellowBeta", "bluegamma"
例如 s1 = "RedAlpha", s2 = "YellowBeta", s3 = "bluegamma";
然后我想稍后对它们中的每一个应用一些不同的逻辑,但我想那是另一回事
我尝试过的代码
int count = 1;
int index = 0;
string s = "";
foreach(string strr in hs)
{
string s + count = strr + str[index]; // I don't know how to make new unique string
count++;
index++;
}
我的其他尝试过的代码,
foreach(string strr in hs)
{
string s = strr + str[index];
s = s + ","
index++;
}
s.split(",");
【问题讨论】:
-
停止。提出问题并将答案转储到您的程序中不会使您成为一名优秀的程序员。退后一步,确保您了解您已经在使用的代码中的内容。然后,当您提出问题并被介绍给新事物时,请研究向您展示的内容。不要只是把一些代码拼凑在一起,就像它们是某种没有人理解的语言的魔法咒语。
-
@BenVoigt 对不起先生。
-
没有理由向我道歉。我只是想通过指出您已经拥有所需的部分(数组)来帮助您更快地改进。
标签: c#