日期:2014-05-20  浏览次数:20875 次

关于匿名方法和匿名对象的问题


var info = () =>
                {
                    //条件
                    if (1 == 1)
                    {
                        return new
                        {
                            name = 1
                        };
                    }
                    return new
                    {
                        name = 2
                    };
                };



为什么不能这样写?创建一个匿名方法,然回一个匿名对象保存在info里。。

------解决方案--------------------
var info = (() =>
                {
                    //条件
                    if (1 == 1)
                    {
                        return new
                        {
                            name = 1
                        };
                    }
                    return new
                    {
                        name = 2
                    };
                })();