質問

I have the following scenario:

private void RequestInfo(string a, string b)
{
   var c = a+b;
   library.FetchInfo(c, OnInfoReceived);
}

private void OnInfoReceived(CustomParameterType object)
{
   dictionaryOfInfo.Add(c, object);
}

As you can see, my problem is that I cannot access variable "c" in the callback passed as argument to FetchInfo function.

役に立ちましたか?

解決

In C# 3.0 and later, you can use a lambda expression like this:

private void RequestInfo(string a, string b)
{
   var c = a+b;
   library.FetchInfo(c, obj => dictionaryOfInfo.Add(c, obj));
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top