-1

I have a string representation of the Guid,I'm doing some testing and I'm hard-coding some GUIDs into the code. The below way can assign Guid of single value.

Guid g = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00");

Now, My question is how i can assign values to an array list of Guid[]?

tartar
  • 140
  • 8
  • 2
    Have you tried a ... loop? Or are you asking how to initialize an array? Latter would be a duplicate of https://stackoverflow.com/questions/5678216/all-possible-array-initialization-syntaxes – Ian Mercer Feb 09 '21 at 05:30
  • [Collection initializers](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers)? – ProgrammingLlama Feb 09 '21 at 05:35
  • Do you know how to assign a value to an array element for, say, an array of integers? – Eric Lippert Feb 09 '21 at 06:53

1 Answers1

0

You can use the below code snippet to assign values to an array list of Guid[]

        Guid[] arr = new Guid[4];
        arr.SetValue(new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"), 0);
        arr.SetValue(new Guid("26a285e5-5435-4daa-8d36-3186bd441cff"), 1);
        arr.SetValue(new Guid("6d850084-d55a-45a9-9e83-5adf22cfbf04"), 2);
        arr.SetValue(new Guid("ec43e526-51c0-41bc-b04a-2f2e72c894cc"), 3);

You can use the below code snippet to fill out your Guid array with randomly generated Guids.

        Guid[] arr = new Guid[10];
        for (int i = 0; i < 10; i++)
        {
            arr.SetValue(Guid.NewGuid(), i);
        }