在TechEd2005中学习C# 2.0新特性时看到??运算符,表示从左向右取第一个不为空的值。这让我联想到Ruby中“||=”运算符的使用:

session[:cart] ||= Cart.new

This method is fairly tricky. It uses Ruby’s conditional assignment operator, ||=. If the session hash has a value corresponding to the key :cart, that value is returned immediately. Otherwise a new cart object is created and assigned to the session. This new cart is then returned.(该段内容引自《Agile Web Development with Rails》一书)

感觉C#2.0中的??运算符很象Ruby的这种用法,但仍然需要进一步改进。刚刚在虚拟机器上装了.net 2005和SQL 2005,有时间深入挖掘一下C# 2.0。

在idior的一篇文章中还曾经讲过C# 2.0模拟Closures的问题,这里不在重复了。等回去后再考证一番。

相关文章:

  • 2022-12-23
  • 2021-10-01
  • 2021-12-09
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2021-06-28
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2021-04-21
  • 2022-03-02
  • 2021-10-20
相关资源
相似解决方案