採取以下程序:序列化對象數組屬性值
using System;
using System.Collections.Generic;
using System.Linq;
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
class Program
{
static void Main()
{
var records = new Person[]
{
new Person{ FirstName = "John", LastName = "Doe", Age = 32 },
new Person{ FirstName = "Jane", LastName = "Doe", Age = 27 },
new Person{ FirstName = "Joe", LastName = "College", Age = 28 }
};
Console.WriteLine(string.Join(", ", records.Select(r => new
{
FullName = r.FirstName + " " + r.LastName
})));
}
}
其預期輸出是:
John Doe, Jane Doe, Joe College
但其實際輸出是:
{ FullName = John Doe }, { FullName = Jane Doe }, { FullName = Joe College }
是否有可能從WriteLine
內部解析此?
這是我最近遇到的一個更大問題的簡化,我需要從WriteLine
內部解決這個問題,因爲我在查詢中執行了這個「序列化」我不能執行一個以上的陳述。
只是刪除新 – user2525463