IntToGuid

public static Guid ToGuid(this int value)
{
    byte[] bytes = new byte[16];
    BitConverter.GetBytes(value).CopyTo(bytes, 0);
    return new Guid(bytes);
}
Example:
class Customer
{
    public Guid Id { get; set; }
    public string Name { get; set; }
}

public IEnumerable<Customer> GetCustomers()
{
    for (int i = 0; i < 10; i++)
    {
        yield return new Customer
        {
            Id = i.ToGuid(),
            Name = "Name " + i
        };
    }
}

Description

Converts an integer to a Guid. This could be used within a unit test to mock objects.

Details

Double click on the code to select all.

 

;