有什么区别
Class1.Method1<Guid, BECustomer>("cId", Facade.Customers.GetSingle);
Run Code Online (Sandbox Code Playgroud)
和
Class1.Method1<Guid, BECustomer>("cId", x => Facade.Customers.GetSingle(x));
Run Code Online (Sandbox Code Playgroud)
?
Resharper建议使用第一个表达式.
我们在一个高流量的网站上,我们想要使用ConcurrentDictionary进行一些非常简单的缓存计算,以防止它为每个请求完成.可能的输入数量足够有限,计算相对较重(拆分和重新连接字符串).
我正在考虑代码
string result;
if (!MyConCurrentDictionary.TryGetValue(someKey, out result))
{
result = DoCalculation(someKey);
// alternative 1: use Item property
MyConcurrentDictionary[someKey] = result;
//alternative 2: use TryAdd
MyConcurrentDictionary.TryAdd(someKey, result);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:从绩效角度来看,哪种替代方案是最佳选择?