私のアプリケーションでSparkPostを使用して、私とクライアントに電子メールを送信しています。これを行うには、C#を使用して配列をシリアル化する必要があります。私は、動作していないように見える次のコードを持っていますが、私は理由を知りません。LINQカスタムタイプのリストから選択してください。
recipients = new List<Recipient>() {
toAddresses.Select(addr => new Recipient() {
address = addr.ToString()
})
}
toAddresses
のメールアドレスを持つだけList<string>
です。
受信者クラス:
class Recipient {
public string address;
}
選択することLINQの出力は次のようになります。
recipients = new List<Recipient>(){
new Recipient() {
address ="[email protected]"
},
new Recipient() {
address ="[email protected]"
},
new Recipient() {
address ="[email protected]"
},
new Recipient() {
address ="[email protected]"
}
}
すべてのヘルプは素晴らしいことだ、ありがとう!
特定のエラー:
Error CS1503 Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable' to 'app.Recipient'
Error CS1950 The best overloaded Add method 'List.Add(Recipient)' for the collection initializer has some invalid arguments
要求ストリング:
wc.UploadString("https://api.sparkpost.com/api/v1/transmissions", JsonConvert.SerializeObject(
new {
options = new {
ip_pool = "sa_shared"
},
content = new {
from = new {
name = "a Sports",
email = "[email protected]"
},
subject = subject,
html = emailBody
},
recipients = new List<Recipient>() {
toAddresses.Select(addr => new Recipient() {
address => addr
})
}
}
))。
現在のコードがどのように機能していないのかを教えてください。エラーメッセージが表示されますか?あなたが期待していたものとは異なる出力? – StriplingWarrior
@StriplingWarrior更新された質問を参照してください。 –