c# set集合 如何清空

在C#中,要清空HashSet集合,可以使用Clear()方法。以下是一个示例:using System;using System.Collections.Generic;class Program{static void Main(){HashSet myHashSet = new HashSet { 1, 2, 3, 4, 5 };Console.WriteLine(

在C#中,要清空HashSet集合,可以使用Clear()方法。以下是一个示例:

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> myHashSet = new HashSet<int> { 1, 2, 3, 4, 5 };
        Console.WriteLine("HashSet before clearing: " + string.Join(", ", myHashSet));

        myHashSet.Clear();
        Console.WriteLine("HashSet after clearing: " + string.Join(", ", myHashSet));
    }
}

输出结果:

HashSet before clearing: 1, 2, 3, 4, 5
HashSet after clearing:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/1204475.html

(0)
派派
上一篇 2024-12-04
下一篇 2024-12-04

发表回复

登录后才能评论