gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
C# 字符串去重
- User
C# 字符串去重
- Assistant
可以使用LINQ的Distinct()方法来对字符串数组进行去重操作。
示例代码如下:
using System; using System.Linq; class Program { static void Main() { string[] strArr = { "abc", "def", "abc", "ghi", "def" }; var distinctStrArr = strArr.Distinct(); foreach (var str in distinctStrArr) { Console.WriteLine(str); } } }输出结果为:
abc def ghi在上述代码中,我们使用了Distinct()方法对字符串数组进行去重操作,然后使用foreach循环遍历并输出去重后的字符串数组。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.