dynamic access to anonymous objects is only supported by .net core. the 4.* runtime does not support
.netcore of dynamic has Bug
波 姜
1
Reputation point
namespace Command
{
public class ClassTest
{
public static dynamic getusers()
{
return new { Id = 1, Name = "test" };
}
}
}
static void Main(string[] args)
{
dynamic u = ClassTest.getusers();
Console.WriteLine(u.Id);
Console.ReadKey();
}
------------------------
this bug------------------------------
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“'object' does not contain a definition for 'Id'”
4 answers
Sort by: Most helpful
-
-
-
Bruce (SqlWork.com) 55,041 Reputation points
2022-10-14T15:15:56.063+00:00 Try net 6
using System; dynamic u = ClassTest.getusers(); Console.WriteLine(u.Id); public class ClassTest { public static dynamic getusers() { return new { Id = 1, Name = "test" }; } }
-
波 姜 1 Reputation point
2022-10-19T02:09:44.777+00:00 But the dynamic type does have bugs