public struct Speakers
{
//...
public bool BackCenter { get; set; }
public bool BackLeft { get; set; }
public bool BackRight { get; set; }
public bool FrontCenter { get; set; }
public bool FrontLeft { get; set; }
public bool FrontLeftOfCenter { get; set; }
public bool FrontRight { get; set; }
public bool FrontRightOfCenter { get; set; }
public bool SideLeft { get; set; }
public bool SideRight { get; set; }
public bool Subwoofer { get; set; }
public bool TopBackCenter { get; set; }
public bool TopBackLeft { get; set; }
public bool TopBackRight { get; set; }
public bool TopCenter { get; set; }
public bool TopFrontCenter { get; set; }
public bool TopFrontLeft { get; set; }
public bool TopFrontRight { get; set; }
}
如何轻松遍历所有这些并将它们设置为false?C#循环并设置结构中的所有字段
不知道它可以帮助你,但默认情况下,他们都是假的。 –
这是来自第三方库,所以不幸的是我不得不使用这个实现:/ – bulltorious
而不是像某些人会建议的那样使用反射,只是创建一个新方法来将它们全部设置为false并咬住子弹。你特别要求一个循环,所以这不是一个答案......只是一个建议。 – SQLMason