Tại sao điều này trở FalseEnum Boxing và Bình đẳng
public enum Directions { Up, Down, Left, Right }
static void Main(string[] args)
{
bool matches = IsOneOf(Directions.Right, Directions.Left, Directions.Right);
Console.WriteLine(matches);
Console.Read();
}
public static bool IsOneOf(Enum self, params Enum[] values)
{
foreach (var value in values)
if (self == value)
return true;
return false;
}
trong khi điều này trả về True?
public static bool IsOneOf(Enum self, params Enum[] values)
{
foreach (var value in values)
if (self.Equals(value))
return true;
return false;
}
Tốt. "Boxing" không thực sự là một lời giải thích đầy đủ, như của bạn. – core
Cảm ơn bạn đã giải thích kỹ thuật! – Greg