想想下面的代码:
static int Main() {
byte[] data = File.ReadAllBytes("anyfile");
SomeMethod(data);
...
}
static void SomeMethod(byte[] data) {
data[0] = anybytevalue; // this line should not be possible!!!
byte b = data[0]; // only reading should be allowed
...
}
有没有办法在 C# 中只读传递 byte[]?抄袭不是解决办法。我不想浪费内存(因为文件可能会变得非常大)。请牢记性能!