C Sharp Enum: Difference between revisions

From Leo's Notes
This page was last edited on 24 February 2017, at 19:14.
m Text replacement - "<code>" to "{{code|"
m Text replacement - "</code>" to "}}"
 
Line 1: Line 1:


== Random Enum Value ==  
== Random Enum Value ==  
Create a new {{code|Random</code> object to use on the code below.
Create a new {{code|Random}} object to use on the code below.
  Array values = Enum.GetValues(typeof(HallEvents));
  Array values = Enum.GetValues(typeof(HallEvents));
  return  (HallEvents) values.GetValue(this.Random.Next(values.Length));
  return  (HallEvents) values.GetValue(this.Random.Next(values.Length));


[[Category:C-Sharp]]
[[Category:C-Sharp]]

Latest revision as of 19:14, 24 February 2017

Random Enum Value

Create a new Random object to use on the code below.

Array values = Enum.GetValues(typeof(HallEvents));
return  (HallEvents) values.GetValue(this.Random.Next(values.Length));