Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,960 questions

51,902 answers

573 users

How to hash a set of GUIDs in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

// A GUID (Globally Unique Identifier) and a UUID (Universally Unique Identifier)
// are essentially the same, both being 128-bit values used to uniquely identify
// information in computer systems.

public class HashGuidsExample
{
    public static void Main(string[] args)
    {
        // Create a HashSet containing three randomly generated GUIDs.
        // Guid.NewGuid() produces a type‑4 GUID.
        var guids = new HashSet<Guid> {
            Guid.NewGuid(),
            Guid.NewGuid(),
            Guid.NewGuid()
        };

        // Compute a hash value for the entire set.
        // HashCode.Combine(...) is idiomatic C# for combining values into a single hash.
        int hash = HashCode.Combine(guids);

        // Print the GUIDs so we can see what was hashed.
        Console.WriteLine("GUIDs in the set:");
        foreach (var g in guids) {
            Console.WriteLine(g);
        }

        // Print the resulting hash value.
        Console.WriteLine("\nHash of the GUID set: " + hash);
    }
}


/*
run:

GUIDs in the set:
e0b30131-cfe2-41f9-ae35-f7636b5547ac
f8265c82-2dd7-43ce-bbd4-e7a2d89ea432
cd1f53d9-2138-4f8e-89a5-1303dc337ceb

Hash of the GUID set: 1876608298

*/

 



answered Jan 7 by avibootz
edited Jan 7 by avibootz
...