【发布时间】:2010-07-18 20:54:48
【问题描述】:
想想下面的代码:
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[]?抄袭不是解决办法。我不想浪费内存(因为文件可能会变得非常大)。请牢记性能!
【问题讨论】:
-
C# 已经在您的标签中。请不要在您的标题中重复此内容。
标签: c# bytearray readonly readonly-collection