English 中文(简体)
该网络是否通过参考或价值支持复印件?
原标题:Does .NET IL support copy by reference or by value?
  • 时间:2012-01-14 00:13:44
  •  标签:
  • cil

仅有。 在C#中,你可以写上<代码>lhs=rhs,如果其指示数按价值复制,请注明编号。

Does the .NET CLI support doing either on any type of object? Can i create a struct Pt { int x, y; } and do something like

Pt pt
var pt_ref=&pt
pt_ref.x=99 //pt.x is now 99
var pt_cpy=pt
pt_cpy.x=88 //nothing else has changed
最佳回答

在IL一级,提及价值类型是一种可能性。 C# disallows them(使用ref等关键词的参数除外),但在C++/CLI中,你可以举以下例子:

value struct Pt
{
    int x;
    int y;
};

void f()
{
    Pt pt;
    Pt% ptRef = pt;
    ptRef.x = 99;
    Pt ptCpy = pt;
    ptCpy.x = 88;
}

然而,其他方式是不可能的。 如果您有参考类型,并填写一份副本,你就会制作一份参考书,而不是参考标本。 如果你想要复制上述物体,你需要写一份功能,复制该物体。

问题回答

暂无回答




相关问题
CIL, CLS, and CTS in .NET

What is the CIL, CTS, and CLS in .NET and what is the difference between them?

What would you use to build a new compiler for .NET?

I m working on a new toy language that will be statically compiled to .NET s IL code. Off hand I can think of the following to actually generate the IL, but I m open to alternatives: Cecil ILASM

Why .NET code compiles to MSIL?

First .NET code compiles to MSIL and then JIT convert it to machine dependent code. Can any one tell me what all benifits get because of the 2 step compilation.Thanks

MSIL Property Setter - Access to the value field

I have the following setter-method, but the object I put in value isn t put through to the called method: .method public hidebysig specialname instance void set_SeatingCapacity(int32 value ) cil ...

Why do I have to do ldarg.0 before calling a field in MSIL?

I want to call a function, with as parameters a string and an Int32. The string is just a literal, the Int32 should be a field. So I thought it should be something like: .method public hidebysig ...

热门标签