xxxxxxxxxx
Random random = new Random();
int randomNumber1 = random.Next(0, 300);
int randomNumber2 = random.Next(0, 300);
xxxxxxxxxx
//In C#, an enum (short for enumeration) is a value type that consists of a set
//of named constants. Enums are useful for defining a set of related values
//that can be used in your code, such as the days of the week or the colors
//of a traffic light.
//Here's an example of an enum in C#:
enum DaysOfWeek
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
//In this example, the DaysOfWeek enum consists of seven named constants:
//Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday.
//Each constant is assigned a default value starting from 0 and incrementing
//by 1 for each subsequent constant. So, for example, Monday is assigned
//the value 0, Tuesday is assigned the value 1, and so on.
//You can use the constants in the enum like this:
DaysOfWeek today = DaysOfWeek.Monday;
if (today == DaysOfWeek.Friday)
{
Console.WriteLine("It's Friday!");
}
xxxxxxxxxx
enum Colors
{
Red = 1,
Green = 2,
Blue = 3
}
//In this example, the Colors enum consists of three named constants:
//Red, Green, and Blue. Each constant is assigned a specific value:
//Red is assigned the value 1, Green is assigned the value 2, and Blue is
//assigned the value 3.
//You can use the constants in the enum like this:
Colors favoriteColor = Colors.Green;
if (favoriteColor == Colors.Red)
{
Console.WriteLine("Your favorite color is red.");
}
else if (favoriteColor == Colors.Green)
{
Console.WriteLine("Your favorite color is green.");
}
else if (favoriteColor == Colors.Blue)
{
Console.WriteLine("Your favorite color is blue.");
}
//Specifying explicit values for the constants in an enum can make your code
//more readable and easier to understand, especially if the values have a
//specific meaning in your application.
xxxxxxxxxx
enum Season
{
Spring,
Summer,
Autumn,
Winter
}
//OR
enum ErrorCode : ushort
{
None = 0,
Unknown = 1,
ConnectionLost = 100,
OutlierReading = 200
}
//OR
[Flags]
public enum Days
{
None = 0b_0000_0000, // 0
Monday = 0b_0000_0001, // 1
Tuesday = 0b_0000_0010, // 2
Wednesday = 0b_0000_0100, // 4
Thursday = 0b_0000_1000, // 8
Friday = 0b_0001_0000, // 16
Saturday = 0b_0010_0000, // 32
Sunday = 0b_0100_0000, // 64
Weekend = Saturday | Sunday
}
xxxxxxxxxx
public enum Enum_example {One, Two, Three, Four}
// Enum_example can have the values: Enum_example.One, Enum_example.Two, Enum_example.Three, Enum_example.Four
public class Example : MonoBehaviour {
Enum_example Enum_Var = Enum_example.Three;
// Enum_Var is a variable with the value Enum_example.three.
}
xxxxxxxxxx
enum Seasons{
Spring, //0
Summer, //1
Autumn, //2
Winter //3
}
enum ErrorCode : uint
{
None = 0,
Unknown, //1
ConnectionLost = 100,
OutlierReading //101
}