Convert an array to a HashSet in .NET












44














How do I convert an array to a hash set ?



string  BlockedList = BlockList.Split(new char { ';' },     
StringSplitOptions.RemoveEmptyEntries);


I need to convert this list to a hashset.










share|improve this question
























  • What kind of list/array is this? What does it contain?
    – Bernard
    Nov 11 '10 at 16:29










  • Calling it BlockList is very misleading. I'd suggest BlockNames.
    – Hans Passant
    Nov 11 '10 at 17:16










  • possible duplicate of How to convert linq results to HashSet or HashedSet
    – nawfal
    Jun 12 '13 at 17:42
















44














How do I convert an array to a hash set ?



string  BlockedList = BlockList.Split(new char { ';' },     
StringSplitOptions.RemoveEmptyEntries);


I need to convert this list to a hashset.










share|improve this question
























  • What kind of list/array is this? What does it contain?
    – Bernard
    Nov 11 '10 at 16:29










  • Calling it BlockList is very misleading. I'd suggest BlockNames.
    – Hans Passant
    Nov 11 '10 at 17:16










  • possible duplicate of How to convert linq results to HashSet or HashedSet
    – nawfal
    Jun 12 '13 at 17:42














44












44








44


1





How do I convert an array to a hash set ?



string  BlockedList = BlockList.Split(new char { ';' },     
StringSplitOptions.RemoveEmptyEntries);


I need to convert this list to a hashset.










share|improve this question















How do I convert an array to a hash set ?



string  BlockedList = BlockList.Split(new char { ';' },     
StringSplitOptions.RemoveEmptyEntries);


I need to convert this list to a hashset.







c# .net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 13 '12 at 9:14









Mahmoud Gamal

64.5k14107136




64.5k14107136










asked Nov 11 '10 at 16:25









devforall

2,602113042




2,602113042












  • What kind of list/array is this? What does it contain?
    – Bernard
    Nov 11 '10 at 16:29










  • Calling it BlockList is very misleading. I'd suggest BlockNames.
    – Hans Passant
    Nov 11 '10 at 17:16










  • possible duplicate of How to convert linq results to HashSet or HashedSet
    – nawfal
    Jun 12 '13 at 17:42


















  • What kind of list/array is this? What does it contain?
    – Bernard
    Nov 11 '10 at 16:29










  • Calling it BlockList is very misleading. I'd suggest BlockNames.
    – Hans Passant
    Nov 11 '10 at 17:16










  • possible duplicate of How to convert linq results to HashSet or HashedSet
    – nawfal
    Jun 12 '13 at 17:42
















What kind of list/array is this? What does it contain?
– Bernard
Nov 11 '10 at 16:29




What kind of list/array is this? What does it contain?
– Bernard
Nov 11 '10 at 16:29












Calling it BlockList is very misleading. I'd suggest BlockNames.
– Hans Passant
Nov 11 '10 at 17:16




Calling it BlockList is very misleading. I'd suggest BlockNames.
– Hans Passant
Nov 11 '10 at 17:16












possible duplicate of How to convert linq results to HashSet or HashedSet
– nawfal
Jun 12 '13 at 17:42




possible duplicate of How to convert linq results to HashSet or HashedSet
– nawfal
Jun 12 '13 at 17:42












7 Answers
7






active

oldest

votes


















83














You do not specify what type BlockedList is, so I will assume it is something that derives from IList (if meant to say String where you wrote BlockList then it would be a string array which derives from IList).



HashSet has a constructor that takes an IEnumerable, so you need merely pass the list into this constructor, as IList derives from IEnumerable.



var set = new HashSet(BlockedList);





share|improve this answer

















  • 3




    Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
    – Jamiec
    Nov 11 '10 at 16:30










  • as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
    – IAbstract
    Nov 11 '10 at 16:32



















13














I'm assuming BlockList is a string (hence the call to Split) which returns a string array.



Just pass the array (which implements IEnumerable) to the constructor of the HashSet:



var hashSet = new HashSet<string>(BlockedList);





share|improve this answer





























    8














    Here is an extension method that will generate a HashSet from any IEnumerable:



    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
    {
    return new HashSet<T>(source);
    }


    To use it with your example above:



    var hashSet = BlockedList.ToHashSet();





    share|improve this answer































      2














      Missed new keyword on extension example....



        public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
      {
      return new HashSet<T>(source);
      }





      share|improve this answer





























        1














        Begining with .Net Framework 4.7.1 and .Net Core 2.0 there is built-in ToHashSet Method



        using System.Linq;

        var hashSet = BlockedList.ToHashSet();





        share|improve this answer





























          0














          To take one step further, the following one-liner demonstrates how you can convert a literal string array to a HashSet, so that you do NOT have to define an intermediate variable SomethingList.



          var directions = new HashSet<string>(new  {"east", "west", "north", "south"});





          share|improve this answer





























            0














            enter image description here



            List<int> a1 = new List<int> { 1, 2 };
            List<int> b1 = new List<int> { 2, 3 };
            List<int> a2 = new List<int> { 1, 2, 3 };
            List<int> b2 = new List<int> { 1, 2, 3 };
            List<int> a3 = new List<int> { 2, 3 };
            List<int> b3 = new List<int> { 1, 2, 3 };

            List<int> a4 = new List<int> { 1, 2, 3 };
            List<int> b4 = new List<int> { 2, 3 };
            List<int> a5 = new List<int> { 1, 2 };
            List<int> b5 = new List<int> { };
            List<int> a6 = new List<int> { };
            List<int> b6 = new List<int> { 1, 2 };
            List<int> a7 = new List<int> { };
            List<int> b7 = new List<int> { };

            HashSet<int> first = new HashSet<int>(a1);
            HashSet<int> second = new HashSet<int>(b1);
            first.Overlaps(second);

            first = new HashSet<int>(a2);
            second = new HashSet<int>(b2);
            first.Overlaps(second);

            first = new HashSet<int>(a3);
            second = new HashSet<int>(b3);
            first.Overlaps(second);

            first = new HashSet<int>(a4);
            second = new HashSet<int>(b4);
            first.Overlaps(second);

            first = new HashSet<int>(a5);
            second = new HashSet<int>(b5);
            first.Overlaps(second);

            first = new HashSet<int>(a6);
            second = new HashSet<int>(b6);
            first.Overlaps(second);

            first = new HashSet<int>(a7);
            second = new HashSet<int>(b7);
            first.SetEquals(second);





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4156626%2fconvert-an-array-to-a-hashsett-in-net%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              83














              You do not specify what type BlockedList is, so I will assume it is something that derives from IList (if meant to say String where you wrote BlockList then it would be a string array which derives from IList).



              HashSet has a constructor that takes an IEnumerable, so you need merely pass the list into this constructor, as IList derives from IEnumerable.



              var set = new HashSet(BlockedList);





              share|improve this answer

















              • 3




                Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
                – Jamiec
                Nov 11 '10 at 16:30










              • as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
                – IAbstract
                Nov 11 '10 at 16:32
















              83














              You do not specify what type BlockedList is, so I will assume it is something that derives from IList (if meant to say String where you wrote BlockList then it would be a string array which derives from IList).



              HashSet has a constructor that takes an IEnumerable, so you need merely pass the list into this constructor, as IList derives from IEnumerable.



              var set = new HashSet(BlockedList);





              share|improve this answer

















              • 3




                Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
                – Jamiec
                Nov 11 '10 at 16:30










              • as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
                – IAbstract
                Nov 11 '10 at 16:32














              83












              83








              83






              You do not specify what type BlockedList is, so I will assume it is something that derives from IList (if meant to say String where you wrote BlockList then it would be a string array which derives from IList).



              HashSet has a constructor that takes an IEnumerable, so you need merely pass the list into this constructor, as IList derives from IEnumerable.



              var set = new HashSet(BlockedList);





              share|improve this answer












              You do not specify what type BlockedList is, so I will assume it is something that derives from IList (if meant to say String where you wrote BlockList then it would be a string array which derives from IList).



              HashSet has a constructor that takes an IEnumerable, so you need merely pass the list into this constructor, as IList derives from IEnumerable.



              var set = new HashSet(BlockedList);






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 11 '10 at 16:27









              Paul Ruane

              27.8k105273




              27.8k105273








              • 3




                Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
                – Jamiec
                Nov 11 '10 at 16:30










              • as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
                – IAbstract
                Nov 11 '10 at 16:32














              • 3




                Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
                – Jamiec
                Nov 11 '10 at 16:30










              • as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
                – IAbstract
                Nov 11 '10 at 16:32








              3




              3




              Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
              – Jamiec
              Nov 11 '10 at 16:30




              Calling Split on this mystery type, with a parameter of char array and StringSplitOptions kinda indicates that BlockedList is a string.
              – Jamiec
              Nov 11 '10 at 16:30












              as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
              – IAbstract
              Nov 11 '10 at 16:32




              as much as I hate making assumptions, looking at the .Split method and StringSplitOptions, I would have to assume String array.
              – IAbstract
              Nov 11 '10 at 16:32













              13














              I'm assuming BlockList is a string (hence the call to Split) which returns a string array.



              Just pass the array (which implements IEnumerable) to the constructor of the HashSet:



              var hashSet = new HashSet<string>(BlockedList);





              share|improve this answer


























                13














                I'm assuming BlockList is a string (hence the call to Split) which returns a string array.



                Just pass the array (which implements IEnumerable) to the constructor of the HashSet:



                var hashSet = new HashSet<string>(BlockedList);





                share|improve this answer
























                  13












                  13








                  13






                  I'm assuming BlockList is a string (hence the call to Split) which returns a string array.



                  Just pass the array (which implements IEnumerable) to the constructor of the HashSet:



                  var hashSet = new HashSet<string>(BlockedList);





                  share|improve this answer












                  I'm assuming BlockList is a string (hence the call to Split) which returns a string array.



                  Just pass the array (which implements IEnumerable) to the constructor of the HashSet:



                  var hashSet = new HashSet<string>(BlockedList);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 '10 at 16:28









                  Justin Niessner

                  208k30360490




                  208k30360490























                      8














                      Here is an extension method that will generate a HashSet from any IEnumerable:



                      public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                      {
                      return new HashSet<T>(source);
                      }


                      To use it with your example above:



                      var hashSet = BlockedList.ToHashSet();





                      share|improve this answer




























                        8














                        Here is an extension method that will generate a HashSet from any IEnumerable:



                        public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                        {
                        return new HashSet<T>(source);
                        }


                        To use it with your example above:



                        var hashSet = BlockedList.ToHashSet();





                        share|improve this answer


























                          8












                          8








                          8






                          Here is an extension method that will generate a HashSet from any IEnumerable:



                          public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                          {
                          return new HashSet<T>(source);
                          }


                          To use it with your example above:



                          var hashSet = BlockedList.ToHashSet();





                          share|improve this answer














                          Here is an extension method that will generate a HashSet from any IEnumerable:



                          public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                          {
                          return new HashSet<T>(source);
                          }


                          To use it with your example above:



                          var hashSet = BlockedList.ToHashSet();






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 23 '13 at 5:01









                          Leniel Maccaferri

                          79.7k33287392




                          79.7k33287392










                          answered Nov 11 '10 at 17:17









                          Jake Pearson

                          17.6k85988




                          17.6k85988























                              2














                              Missed new keyword on extension example....



                                public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                              {
                              return new HashSet<T>(source);
                              }





                              share|improve this answer


























                                2














                                Missed new keyword on extension example....



                                  public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                                {
                                return new HashSet<T>(source);
                                }





                                share|improve this answer
























                                  2












                                  2








                                  2






                                  Missed new keyword on extension example....



                                    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                                  {
                                  return new HashSet<T>(source);
                                  }





                                  share|improve this answer












                                  Missed new keyword on extension example....



                                    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
                                  {
                                  return new HashSet<T>(source);
                                  }






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Dec 9 '10 at 16:05









                                  CountZero

                                  3,28733546




                                  3,28733546























                                      1














                                      Begining with .Net Framework 4.7.1 and .Net Core 2.0 there is built-in ToHashSet Method



                                      using System.Linq;

                                      var hashSet = BlockedList.ToHashSet();





                                      share|improve this answer


























                                        1














                                        Begining with .Net Framework 4.7.1 and .Net Core 2.0 there is built-in ToHashSet Method



                                        using System.Linq;

                                        var hashSet = BlockedList.ToHashSet();





                                        share|improve this answer
























                                          1












                                          1








                                          1






                                          Begining with .Net Framework 4.7.1 and .Net Core 2.0 there is built-in ToHashSet Method



                                          using System.Linq;

                                          var hashSet = BlockedList.ToHashSet();





                                          share|improve this answer












                                          Begining with .Net Framework 4.7.1 and .Net Core 2.0 there is built-in ToHashSet Method



                                          using System.Linq;

                                          var hashSet = BlockedList.ToHashSet();






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Jun 6 '18 at 12:45









                                          Stas Boyarincev

                                          1,247911




                                          1,247911























                                              0














                                              To take one step further, the following one-liner demonstrates how you can convert a literal string array to a HashSet, so that you do NOT have to define an intermediate variable SomethingList.



                                              var directions = new HashSet<string>(new  {"east", "west", "north", "south"});





                                              share|improve this answer


























                                                0














                                                To take one step further, the following one-liner demonstrates how you can convert a literal string array to a HashSet, so that you do NOT have to define an intermediate variable SomethingList.



                                                var directions = new HashSet<string>(new  {"east", "west", "north", "south"});





                                                share|improve this answer
























                                                  0












                                                  0








                                                  0






                                                  To take one step further, the following one-liner demonstrates how you can convert a literal string array to a HashSet, so that you do NOT have to define an intermediate variable SomethingList.



                                                  var directions = new HashSet<string>(new  {"east", "west", "north", "south"});





                                                  share|improve this answer












                                                  To take one step further, the following one-liner demonstrates how you can convert a literal string array to a HashSet, so that you do NOT have to define an intermediate variable SomethingList.



                                                  var directions = new HashSet<string>(new  {"east", "west", "north", "south"});






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jul 26 '17 at 23:36









                                                  RayLuo

                                                  6,00223946




                                                  6,00223946























                                                      0














                                                      enter image description here



                                                      List<int> a1 = new List<int> { 1, 2 };
                                                      List<int> b1 = new List<int> { 2, 3 };
                                                      List<int> a2 = new List<int> { 1, 2, 3 };
                                                      List<int> b2 = new List<int> { 1, 2, 3 };
                                                      List<int> a3 = new List<int> { 2, 3 };
                                                      List<int> b3 = new List<int> { 1, 2, 3 };

                                                      List<int> a4 = new List<int> { 1, 2, 3 };
                                                      List<int> b4 = new List<int> { 2, 3 };
                                                      List<int> a5 = new List<int> { 1, 2 };
                                                      List<int> b5 = new List<int> { };
                                                      List<int> a6 = new List<int> { };
                                                      List<int> b6 = new List<int> { 1, 2 };
                                                      List<int> a7 = new List<int> { };
                                                      List<int> b7 = new List<int> { };

                                                      HashSet<int> first = new HashSet<int>(a1);
                                                      HashSet<int> second = new HashSet<int>(b1);
                                                      first.Overlaps(second);

                                                      first = new HashSet<int>(a2);
                                                      second = new HashSet<int>(b2);
                                                      first.Overlaps(second);

                                                      first = new HashSet<int>(a3);
                                                      second = new HashSet<int>(b3);
                                                      first.Overlaps(second);

                                                      first = new HashSet<int>(a4);
                                                      second = new HashSet<int>(b4);
                                                      first.Overlaps(second);

                                                      first = new HashSet<int>(a5);
                                                      second = new HashSet<int>(b5);
                                                      first.Overlaps(second);

                                                      first = new HashSet<int>(a6);
                                                      second = new HashSet<int>(b6);
                                                      first.Overlaps(second);

                                                      first = new HashSet<int>(a7);
                                                      second = new HashSet<int>(b7);
                                                      first.SetEquals(second);





                                                      share|improve this answer




























                                                        0














                                                        enter image description here



                                                        List<int> a1 = new List<int> { 1, 2 };
                                                        List<int> b1 = new List<int> { 2, 3 };
                                                        List<int> a2 = new List<int> { 1, 2, 3 };
                                                        List<int> b2 = new List<int> { 1, 2, 3 };
                                                        List<int> a3 = new List<int> { 2, 3 };
                                                        List<int> b3 = new List<int> { 1, 2, 3 };

                                                        List<int> a4 = new List<int> { 1, 2, 3 };
                                                        List<int> b4 = new List<int> { 2, 3 };
                                                        List<int> a5 = new List<int> { 1, 2 };
                                                        List<int> b5 = new List<int> { };
                                                        List<int> a6 = new List<int> { };
                                                        List<int> b6 = new List<int> { 1, 2 };
                                                        List<int> a7 = new List<int> { };
                                                        List<int> b7 = new List<int> { };

                                                        HashSet<int> first = new HashSet<int>(a1);
                                                        HashSet<int> second = new HashSet<int>(b1);
                                                        first.Overlaps(second);

                                                        first = new HashSet<int>(a2);
                                                        second = new HashSet<int>(b2);
                                                        first.Overlaps(second);

                                                        first = new HashSet<int>(a3);
                                                        second = new HashSet<int>(b3);
                                                        first.Overlaps(second);

                                                        first = new HashSet<int>(a4);
                                                        second = new HashSet<int>(b4);
                                                        first.Overlaps(second);

                                                        first = new HashSet<int>(a5);
                                                        second = new HashSet<int>(b5);
                                                        first.Overlaps(second);

                                                        first = new HashSet<int>(a6);
                                                        second = new HashSet<int>(b6);
                                                        first.Overlaps(second);

                                                        first = new HashSet<int>(a7);
                                                        second = new HashSet<int>(b7);
                                                        first.SetEquals(second);





                                                        share|improve this answer


























                                                          0












                                                          0








                                                          0






                                                          enter image description here



                                                          List<int> a1 = new List<int> { 1, 2 };
                                                          List<int> b1 = new List<int> { 2, 3 };
                                                          List<int> a2 = new List<int> { 1, 2, 3 };
                                                          List<int> b2 = new List<int> { 1, 2, 3 };
                                                          List<int> a3 = new List<int> { 2, 3 };
                                                          List<int> b3 = new List<int> { 1, 2, 3 };

                                                          List<int> a4 = new List<int> { 1, 2, 3 };
                                                          List<int> b4 = new List<int> { 2, 3 };
                                                          List<int> a5 = new List<int> { 1, 2 };
                                                          List<int> b5 = new List<int> { };
                                                          List<int> a6 = new List<int> { };
                                                          List<int> b6 = new List<int> { 1, 2 };
                                                          List<int> a7 = new List<int> { };
                                                          List<int> b7 = new List<int> { };

                                                          HashSet<int> first = new HashSet<int>(a1);
                                                          HashSet<int> second = new HashSet<int>(b1);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a2);
                                                          second = new HashSet<int>(b2);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a3);
                                                          second = new HashSet<int>(b3);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a4);
                                                          second = new HashSet<int>(b4);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a5);
                                                          second = new HashSet<int>(b5);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a6);
                                                          second = new HashSet<int>(b6);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a7);
                                                          second = new HashSet<int>(b7);
                                                          first.SetEquals(second);





                                                          share|improve this answer














                                                          enter image description here



                                                          List<int> a1 = new List<int> { 1, 2 };
                                                          List<int> b1 = new List<int> { 2, 3 };
                                                          List<int> a2 = new List<int> { 1, 2, 3 };
                                                          List<int> b2 = new List<int> { 1, 2, 3 };
                                                          List<int> a3 = new List<int> { 2, 3 };
                                                          List<int> b3 = new List<int> { 1, 2, 3 };

                                                          List<int> a4 = new List<int> { 1, 2, 3 };
                                                          List<int> b4 = new List<int> { 2, 3 };
                                                          List<int> a5 = new List<int> { 1, 2 };
                                                          List<int> b5 = new List<int> { };
                                                          List<int> a6 = new List<int> { };
                                                          List<int> b6 = new List<int> { 1, 2 };
                                                          List<int> a7 = new List<int> { };
                                                          List<int> b7 = new List<int> { };

                                                          HashSet<int> first = new HashSet<int>(a1);
                                                          HashSet<int> second = new HashSet<int>(b1);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a2);
                                                          second = new HashSet<int>(b2);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a3);
                                                          second = new HashSet<int>(b3);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a4);
                                                          second = new HashSet<int>(b4);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a5);
                                                          second = new HashSet<int>(b5);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a6);
                                                          second = new HashSet<int>(b6);
                                                          first.Overlaps(second);

                                                          first = new HashSet<int>(a7);
                                                          second = new HashSet<int>(b7);
                                                          first.SetEquals(second);






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Nov 23 '18 at 1:22

























                                                          answered Nov 23 '18 at 1:04









                                                          Hemendr

                                                          18218




                                                          18218






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Stack Overflow!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.





                                                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                              Please pay close attention to the following guidance:


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4156626%2fconvert-an-array-to-a-hashsett-in-net%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Sphinx de Gizeh

                                                              Dijon

                                                              Guerrita