2
デリゲートは、関数を参照する参照型であることがわかります。スタックとrvariableにメモリが割り当てられc#.netのデリゲートへのメモリ割り当てのメカニズム
using System;
namespace Testing_Delegates
{
class Program
{
delegate void fun_delegate();
fun_delegate response;
static void Main(string[] args)
{
Program p = new Program();
p.fun();//Calling function directly
p.response += p.fun;//Setting reference to the function via delegate
}
public void fun()
{
int lvariable = 10000;
string rvariable = "Hello Developers!";
Console.WriteLine(lvariable + " " + rvariable);
}
}
}
我々は関数(FUN)内のローカル変数はlvariable知っているように文字列が格納され、ヒープのメモリ位置への参照を含みます。今
、
彼ら(fun_delegateと応答が)かどうかをスタックまたはヒープ上に、メモリを割り当てる
- 我々は、デリゲートまたはデリゲートのインスタンスを定義し、?
- なぜそれを任意の関数に参照するためにデリゲートのインスタンスを作成する必要があるのですか?彼ら (fun_delegateと応答が)かどうかをスタック上または ヒープ上に、メモリを割り当てる
この投稿をチェックしたいかもしれません。http://stackoverflow.com/questions/22431902/where-variables-of-a-function-is-store-on-stack-or-heap – Rahul