Expando Object 和 IEnumerable returns 无法将 void 隐式转换为对象
Expando Object and IEnumerable returns cannot convert implicitly void to object
此代码正在抛出错误 'cannot implicitly convert type void to object'
dynamic disruption1 = new ExpandoObject();
disruption1.locationsAffected = new string[] { "london", "panama" };
IEnumerable<dynamic> disruptionList = new List<dynamic>().Add(disruption1);
但是我不确定是哪里出了问题,我也试过了
dynamic disruptionList = new List<dynamic>().Add(disruption1);
它不会抛出错误,但不是我需要的。
我正在创建单元测试。
Add()
方法的 return 类型是 void
并且您试图将 void
分配给 List<dynamic>
类型的变量,这是绝对不允许的并且编译器将抛出您所看到的错误,因为您已经引用了 List<T>
,按照以下方式在新行中添加项目:
dynamic disruptionList = new List<dynamic>();
disruptionList.Add(disruption1);
此代码正在抛出错误 'cannot implicitly convert type void to object'
dynamic disruption1 = new ExpandoObject();
disruption1.locationsAffected = new string[] { "london", "panama" };
IEnumerable<dynamic> disruptionList = new List<dynamic>().Add(disruption1);
但是我不确定是哪里出了问题,我也试过了
dynamic disruptionList = new List<dynamic>().Add(disruption1);
它不会抛出错误,但不是我需要的。
我正在创建单元测试。
Add()
方法的 return 类型是 void
并且您试图将 void
分配给 List<dynamic>
类型的变量,这是绝对不允许的并且编译器将抛出您所看到的错误,因为您已经引用了 List<T>
,按照以下方式在新行中添加项目:
dynamic disruptionList = new List<dynamic>();
disruptionList.Add(disruption1);