public IsFree(byte[] Raw) { if (Raw == null) return true; foreach (byte b in Raw) if (b != 0xFF) return false; return true; } Is it possible to make the check shorter / more beautiful? The void is exactly 0xFF
var bytes = new byte[] { /*...*/ }; if (bytes.IsEmpty()) { //.. } public static class BytesExtensions { public static bool IsEmpty(this byte[] source, byte value = 0xFF) { return source == null || source.All(x => x == value); } } bool IsEmpty = Raw?.All(b => (b==0xFF))??false; - Aliasbool IsEmpty = Raw?.All(x => x==0xFF)??true; - pavelipSource: https://ru.stackoverflow.com/questions/778683/
All Articles
Linqfor example, there is anallmethod for enumeration. more introductory! PS: betterisEmptyname - teranRtlEqualMemoryfor comparison. - Lunar Whisperrepe scasborrepne scasb, perhaps there is a WinAPI wrapper over it. But this is more about performance than about length. - Lunar Whisper