0

What am I doing wrong. C#, random.next method, enumerator left or right ternary operator.

Enum.Parse(random.Next(0, 2) == 0 ? HorizontalDirection.Left : HorizontalDirection.Right); random.next takes a value of 0 or 1, if 0 the enumeration goes left, else right. I've been stuck on this for quite some time.

8th Oct 2020, 4:36 AM
Dylan
Dylan - avatar
3 odpowiedzi
0
As an update this is solved. var rand = random.Next(0, 2); HorizontalDirection direction = rand == 0 ? HorizontalDirection.Left : HorizontalDirection.Right; What I needed was a random that would randomly decide the direction the object would move being either left or right (0,2) using my HorizontalDirection enum which is its own class. Thank you for your input and I apologize about not including enough context.
8th Oct 2020, 6:21 AM
Dylan
Dylan - avatar