I'm trying: RandomBytes
generates random bytes (so, it's enumerable). RandomNBytes
is the same but N
random bytes (it extends RandomBytes
). So, code is:
class RandomBytes : IEnumerable<byte>, IEnumerable {
public IEnumerator<byte> GetEnumerator() {
var rnd = new Random();
while (true) {
yield return (byte)rnd.Next(0, 255);
}
}
IEnumerator IEnumerable.GetEnumerator() {
return this.GetEnumerator();
}
}
class RandomNBytes : RandomBytes {
readonly UInt64 Count;
RandomNBytes (UInt64 count) {
Count = count;
}
public new IEnumerator<byte> GetEnumerator() {
return ((IEnumerable<byte>)base).Take(Count);
}
}
But there is a problem with base
, VC raises error: Use of keyword "base" is not valid in this context. How to call Take()
over base-class enumerable?