Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字典和对象之间的C#-三元运算符[]_C#_Arrays_Linq_Object - Fatal编程技术网

字典和对象之间的C#-三元运算符[]

字典和对象之间的C#-三元运算符[],c#,arrays,linq,object,C#,Arrays,Linq,Object,如何在C#中的字典类型和对象数组之间实现三元运算符 我试着吼叫,但给了我错误: System.Collections.Generic.IEnumerable“和”对象[] public async Task NovoEmail(Escrita.Email email) { try { var response = await $"{_configuration["MicrosoftGraph:Url&qu

如何在C#中的字典类型和对象数组之间实现三元运算符

我试着吼叫,但给了我错误:

System.Collections.Generic.IEnumerable“和”对象[]

    public async Task NovoEmail(Escrita.Email email)
    {
        try
        {
            var response = await $"{_configuration["MicrosoftGraph:Url"]}/users/{email.Remetente}/sendMail"
                            .WithOAuthBearerToken(await _graph.Token())
                            .PostJsonAsync(new
                            {
                                message = new
                                {
                                    subject = email.Assunto,
                                    body = new { contentType = "HTML", content = email.Corpo },
                                    toRecipients = email.Destinatarios.Select(destinatario => new { emailAddress = new { address = destinatario } }),
                                    ccRecipients = email.Copias.Select(copia => new { emailAddress = new { address = copia } }),
                                    attachments = email.Anexos.Count > 0 ? email.Anexos.Select(anexo => new Dictionary<string, string> {
                                        { "@odata.type", "#microsoft.graph.fileAttachment" },
                                        { "name", anexo.FileName },
                                        { "contentType", anexo.ContentType },
                                        { "contentBytes", _base64.FormFileToBase64(anexo) }
                                     }) : new object[] { }
                                }
                            });

            response.EnsureSuccessStatusCode();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
公共异步任务电子邮件(Escrita.Email)
{
尝试
{
var response=wait$“{u配置[“MicrosoftGraph:Url”]}/users/{email.remeente}/sendMail”
.WithOAuthBeareToken(wait_graph.Token())
.PostJsonAsync(新版本)
{
消息=新
{
主题=email.Assunto,
body=new{contentType=“HTML”,content=email.Corpo},
toRecipients=email.Destinatarios.Select(destinatario=>new{emailAddress=new{address=destinatario}),
ccRecipients=email.Copias.Select(copia=>new{emailAddress=new{address=copia}),
附件=email.Anexos.Count>0?email.Anexos.Select(anexo=>newdictionary{
{“@odata.type”、“#microsoft.graph.fileAttachment”},
{“name”,anexo.FileName},
{“contentType”,anexo.contentType},
{“contentBytes”,_base64.FormFileToBase64(anexo)}
}):新对象[]{}
}
});
response.EnsureSuccessStatusCode();
}
捕获(例外情况除外)
{
掷骰子;
}
}

零元素条件不需要三元运算符:没有它,您将得到一个
IEnumerable()


零元素条件不需要三元运算符:没有它,您将得到一个
IEnumerable()


如果您使用
新字典()
,该怎么办?(或
null
)使用
new Dictionary()
而不是这个
new object[]
我认为您的代码会抛出运行时异常,即
已经添加了一个具有相同键的项。
如果有多个
Anexos
为什么还要测试
>0
email.Anexos.Select(…)
如果没有项目,将返回空枚举。如果您确实需要它,那么它是
可枚举的.Empty()
您需要匹配
Select
@IanMercer同意,这似乎不需要。如果有人坚持,我也会选择Enumerable.Empty()尽管。如果你使用
新字典()
?(或
null
)使用
new Dictionary()
而不是这个
new object[]
我认为您的代码会抛出运行时异常,即
已经添加了一个具有相同键的项。
如果有多个
Anexos
为什么还要测试
>0
email.Anexos.Select(…)
如果没有项目,将返回空枚举。如果您确实需要它,那么它是
可枚举的.Empty()
您需要匹配
Select
@IanMercer同意,这似乎不需要。如果有人坚持,我也会选择Enumerable.Empty()。
email.Anexos.Select(anexo => new Dictionary<string, string> {
                                    { "@odata.type", "#microsoft.graph.fileAttachment" },
                                    { "name", anexo.FileName },
                                    { "contentType", anexo.ContentType },
                                    { "contentBytes", _base64.FormFileToBase64(anexo) }
                                 })
Enumerable.Empty<Dictionary<string,string>>()