【发布时间】:2020-03-21 12:54:00
【问题描述】:
我想弄清楚为什么下面的“Console.WriteLine(x)”可以直接打印匿名对象的对象?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class program
{
static void Main()
{
var groupA = new[] { 3, 4, 5, 6 };
var groupB = new[] { 6, 7, 8, 9 };
var someInts = from a in groupA
from b in groupB
where a > 4 && b <= 8
select new { a, b, sum = a + b }; // object of Anonymous tyoe
foreach (var x in someInts)
Console.WriteLine(x); // ok
// Console.WriteLine(groupA); // nok
}
}
【问题讨论】:
-
这能回答你的问题吗? How does ToString on an anonymous type work?
标签: c# console.writeline